加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

xaml – 未检测到已安装的组件.无法解析TargetName HighContrast

发布时间:2020-12-14 02:51:21 所属栏目:Windows 来源:网络整理
导读:我的CommandBar在XAML中将其IsOpen属性设置为true,因此每个按钮的文本都是可见的,因为我希望描述保持可见. 当我点击省略号按钮时,它会隐藏文本,第二次点击它时,我收到以下错误: 未检测到已安装的组件.无法解析TargetName HighContrastBorder. 用户界面有些
我的CommandBar在XAML中将其IsOpen属性设置为true,因此每个按钮的文本都是可见的,因为我希望描述保持可见.

当我点击省略号按钮时,它会隐藏文本,第二次点击它时,我收到以下错误:

未检测到已安装的组件.无法解析TargetName HighContrastBorder.

用户界面有些尴尬,可能与此有关,但我无法弄清楚是什么或为什么:

enter image description here

正如您所看到的,我正在显示的各种按钮的按钮文字被截断:

代码方面,据我所知,它并没有什么特别之处:

<Page.BottomAppBar>
    <CommandBar IsOpen="True" 
                ClosedDisplayMode="Compact" 
                IsSticky="True"
                Visibility="{Binding 
                CommandBarViewModel.IsCommandBarVisible,Converter={StaticResource BoolToVisibilityConverter}}"
                Background="{ThemeResource SystemControlBackgroundAccentBrush}">

        <AppBarButton 
            Icon="Add" 
            Label="Add" 
            Foreground="White"
            Command="{Binding CommandBarViewModel.AddCommand}"
            Visibility="{Binding CommandBarViewModel.IsAddVisible,Converter={StaticResource BoolToVisibilityConverter}}"/>

        <AppBarButton 
            Icon="Refresh" 
            Label="Refresh" 
            Foreground="White" 
            Command="{Binding CommandBarViewModel.RefreshListCommand}" 
            Visibility="{Binding 
            CommandBarViewModel.IsRefreshListVisible,Converter={StaticResource BoolToVisibilityConverter}}"/>
    </CommandBar>
</Page.BottomAppBar>

没有InnerException,并且从App.g.i.cs抛出异常

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
 UnhandledException += (sender,e) =>
        {
            if (global::System.Diagnostics.Debugger.IsAttached) 
            global::System.Diagnostics.Debugger.Break();
        };
#endif

关于我的问题,即文本截止和未处理的异常的任何想法?

谢谢

更新 – 1:

当我从CommandBar的Visible属性中删除binded属性(CommandBarViewModel.IsCommandBarVisible)并将其硬编码为Visible时,错误向下移动而不是在App.gics中发生,它现在发生了第一个绑定属性按钮它试图设置ie的可见性

<AppBarButton 
            Icon="Add" 
            Label="Add" 
            Foreground="White"
            Command="{Binding CommandBarViewModel.AddCommand}"
            Visibility="{Binding CommandBarViewModel.IsAddVisible,Converter={StaticResource BoolToVisibilityConverter}}"/>

但是这次我收到以下错误:

An exception of type 'System.Runtime.InteropServices.COMException' 
occurred in GalaSoft.MvvmLight.dll but was not handled in user code

WinRT information: Cannot resolve TargetName HighContrastBorder.

Additional information: No installed components were detected.

你可以看到类似,但它似乎来自MVVMLight ???没有意义!

有关如何解决此问题的任何建议/想法?

更新 – 2:

如果我删除所有可见性属性(及其相应的绑定),相应地显示命令(即没有更多的截止文本),我可以一遍又一遍地点击省略号按钮,它不再崩溃!

所以它肯定与Visibility相关并将它绑定到视图模型的属性,但究竟是什么,我不知道.

可能是ViewModel仅在页面加载时构建,在此阶段,CommandBar和它的按钮被正确初始化为时已晚.

奇怪的是,关于显示/隐藏按钮的所有内容都按预期工作,除了我的文本被截断,我无法点击省略号按钮或它崩溃.

更新 – 3:

我发现了一个解决方法,我并没有因为我认为这是错误而上下跳动,但现在它会这样做.为了避免这个错误,我确保在初始化ViewModel时将命令栏和按钮设置为可见,然后根据它所在的页面相应地隐藏它们.

公共类AppShellViewModel
{
????public void AppShellViewModel
????{
??????this.CommandBarViewModel.IsCommandBarVisible = true;
??????this.CommandBarViewModel.IsAddVisible = true;
??????this.CommandBarViewModel.IsRefreshVisible = true;
??????this.CommandBarViewModel.IsCancelVisible = true;
????}

...

Hide buttons accordingly in the various parts of your app.
this.CommandBarViewModel.IsCancelVisible = false;

}

就个人而言,我觉得这是一个CommandBar控件和按钮的错误,因为我应该能够从它开始隐藏它(和它的按钮)它应该

a)能够毫无错误地处理这个问题.
???b)能够在没有文本切断的情况下正确地“重绘”自身.

我当然可能是错的,它可能与我的代码有关,但从我的角度来看,删除可见性绑定修复它并使其可见首先修复它,所以它似乎指向这种方式.

更新 – 4:

这是实际的代码.我尽可能地简化了它(即删除了名称空间,DataTemplates,主要内容等等),只留下了CommandBar及其按钮.希望这会有所帮助.

正如您在使用mvvmlight时所看到的,我的源设置为Locatorand,我的路径设置为相关的ViewModel,在本例中为AppShellViewModel.

然而正如Grace所解释的,当我使用x:bind而不是绑定时,我收到以下错误:

Invalid binding path 'CommandBarViewModel.IsCommandBarVisible' :
Property 'CommandBarViewModel' can't be found on type 'AppShell'    
MyApp ..MyAppViewsAppShell.xaml

XAML代码:
????????

<Page.Resources>
        <converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
        <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
        <x:Double x:Key="EllipseDimension">30</x:Double>
    </Page.Resources>

    <Page.BottomAppBar>
        <CommandBar x:Name="AppBar"
                    IsOpen="{x:Bind CommandBarViewModel.IsCommandBarVisible}" 
                    ClosedDisplayMode="Compact" 
                    IsSticky="{x:Bind CommandBarViewModel.IsCommandBarVisible}"
                    Visibility="{x:Bind CommandBarViewModel.IsCommandBarVisible,Converter={StaticResource BoolToVisibilityConverter}}"
                    Background="{ThemeResource SystemControlBackgroundAccentBrush}"
                    IsEnabled="{x:Bind IsNotBusy}">
            <AppBarButton 
                Icon="Add" 
                Label="Add" 
                Foreground="White"
                Command="{x:Bind CommandBarViewModel.RegisterCommand}"
                Visibility="{x:Bind CommandBarViewModel.IsRegisterVisible,Converter={StaticResource BoolToVisibilityConverter}}"/>

            <AppBarButton 
                Icon="Refresh" 
                Label="Refresh" 
                Foreground="White" 
                Command="{x:Bind CommandBarViewModel.RefreshListCommand}" 
                Visibility="{x:Bind CommandBarViewModel.IsRefreshListVisible,Converter={StaticResource BoolToVisibilityConverter}}"/>
        </CommandBar>
    </Page.BottomAppBar>
</Page>

谢谢.

解决方法

我用你的代码创建了一个示例项目:

XAML:

<Page
    x:Class="CommandBarSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CommandBarSample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" x:Name="root">

    </Grid>

    <Page.BottomAppBar>

            <CommandBar IsOpen="True" 
                IsSticky="True"
                        ClosedDisplayMode="Compact"
                Background="{ThemeResource SystemControlBackgroundAccentBrush}">

                <AppBarButton 
            Icon="Add" 
            Label="Add" 
            Foreground="White"
            Command="{Binding CommandBarViewModel.RegisterCardCommand}"
            />

                <AppBarButton 
            Icon="Refresh" 
            Label="Refresh" 
            Foreground="White" 
            Command="{Binding CommandBarViewModel.RefreshCardListCommand}" 
            />
            </CommandBar>

    </Page.BottomAppBar>
</Page>

xaml.cs:

默认模板,不更改任何内容.

我无法重现您的异常和UI错误,这是我的猜测:在项目的某个地方,您提到HighContrastBorder作为样式的目标.我建议你在其他地方找到并修复它,你发布的代码正在运行.我的版本是14316桌面.

UPDATE

我将Visibility =“{Binding ShowButton}”添加到AppBarButton中,添加this.DataContext = this;到xaml.cs的构造函数

在xaml.cs中添加以下内容:

private bool _ShowButton = true;

        public bool ShowButton
        {
            get
            {
                return _ShowButton;
            }
            set
            {
                Set(ref _ShowButton,value);
            }
        }

        private void Set(ref bool _ShowButton,bool value,[CallerMemberName] string property = "")
        {
            _ShowButton = value;
            NotifyPropertyChanged(property);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this,new PropertyChangedEventArgs(info));
            }
        }

当我更改ShowButton值时,Visibility会相应更新.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读