Xaml 未检测到已安装的组件。无法解析TargetName HighControlBorder-UWP Windows 10

Xaml 未检测到已安装的组件。无法解析TargetName HighControlBorder-UWP Windows 10,xaml,win-universal-app,windows-10-universal,uwp-xaml,Xaml,Win Universal App,Windows 10 Universal,Uwp Xaml,我的CommandBar在XAML中将其IsOpen属性设置为true,因此每个按钮的is文本都是可见的,因为我希望描述保持可见 当我单击省略号按钮时,它会隐藏文本,第二次单击它时,我得到以下错误: An exception of type 'System.Runtime.InteropServices.COMException' occurred in GalaSoft.MvvmLight.dll but was not handled in user code WinRT informa

我的
CommandBar
在XAML中将其IsOpen属性设置为true,因此每个按钮的is文本都是可见的,因为我希望描述保持可见

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

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.
Invalid binding path 'CommandBarViewModel.IsCommandBarVisible' :
Property 'CommandBarViewModel' can't be found on type 'AppShell'    
MyApp ..\MyApp\Views\AppShell.xaml
未检测到已安装的组件。无法解析TargetName HighControlBorder

UI出现了一些尴尬的情况,可能与此有关,但我不知道是什么或为什么:

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

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

<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>
关于我的问题,即文本截断和未处理的异常,有什么想法吗

谢谢

更新-1:

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

        <AppBarButton 
            Icon="Add" 
            Label="Add" 
            Foreground="White"
            Command="{Binding CommandBarViewModel.AddCommand}"
            Visibility="{Binding CommandBarViewModel.IsAddVisible,
                         Converter={StaticResource BoolToVisibilityConverter}}"/>
就像你看到的一样,但它似乎来自MVLight???没道理

关于如何解决这个问题有什么建议/想法吗

更新-2:

如果我删除所有可见性属性(及其相应的绑定),命令将相应显示(即不再显示截断文本),我可以反复单击省略号按钮,它不再崩溃

因此,它肯定与可见性相关,并将其绑定到视图模型的属性,但具体是什么,我不知道

可能是ViewModel仅在页面加载时构建,在这个阶段,命令栏及其按钮要正确初始化已经太晚了

奇怪的是,关于显示/隐藏按钮的一切都按预期进行,除了我的文本被切断,我不能点击省略号按钮,否则它会崩溃

更新-3:

我找到了一份工作,我不会因为我觉得这是错误的而跳上跳下,但现在就可以了。为了避免此错误,我确保在初始化ViewModel时将命令栏和按钮设置为可见,然后根据它所在的页面相应地隐藏它们

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

}

就我个人而言,我觉得CommandBar控件和按钮是一个bug,因为我应该能够在启动时隐藏它(和它的按钮),而且它应该可以

a) 能够在没有任何错误的情况下处理此问题。 b) 能够在不切断文本的情况下正确地“重画”自身

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

更新-4:

这是实际的代码。我尽可能地简化了它(即删除了名称空间、数据模板、主要内容等),只保留了命令栏及其按钮。希望这会有所帮助

正如您在使用mvvmlight时所看到的,我的源设置为
定位器
,我的路径设置为相关的
视图模型
,在本例中为AppShellViewModel

然而,正如格雷斯所解释的,当我使用x:bind而不是binding时,我得到了以下错误:

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.
Invalid binding path 'CommandBarViewModel.IsCommandBarVisible' :
Property 'CommandBarViewModel' can't be found on type 'AppShell'    
MyApp ..\MyApp\Views\AppShell.xaml

XAML代码:


30

谢谢。

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

xaml:

当我更改
ShowButton
值时,可见性会相应地更新

没有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
当代码运行时,
添加
按钮或
刷新
按钮在一开始就设置为不可见时,我可以重现此问题

要解决此问题,可以使用
x:Bind
而不是
Binding
。{x:Bind}执行它在编译时生成的专用代码,{Binding}使用通用运行时对象检查

如果首先将
IsAddVisible
IsRefreshListVisible
设置为“false”(不可见),则它不会生成匹配的
AppbarButton
,使用
绑定将发生错误。例如,您使用
x:Bind
刷新
按钮设置为不可见,并将
添加
按钮设置为可见,您会发现
命令栏中没有
刷新
按钮的空间,
添加
按钮将替换该按钮。这可以证实我的观点,如果在初始化
命令栏时将
false
设置为
AppbarButton
,则不会生成此按钮

未检测到已安装的组件。无法解析TargetName HighControlBorder

如果选中,您将看到
命令栏内有一个名为
高对比度边框的
矩形

或者,您可以在代码运行时使用实时可视化树查找此
高对比度边框

如您所见,它是
CommandBar
ContentRoot
中的
矩形

我既不能重现这个问题,也不能重现文本截断问题,它们在我身边总是很好。我正在使用MVVM,但是我没有使用MVVMLight来测试这个问题。也许是
<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>
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));
            }
        }
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
 UnhandledException += (sender, e) =>
        {
            if (global::System.Diagnostics.Debugger.IsAttached) 
            global::System.Diagnostics.Debugger.Break();
        };
#endif