未检测到已安装的组件.无法解析 TargetName HighContrastBorder - UWP Windows 10 [英] No installed components were detected. Cannot resolve TargetName HighContrastBorder - UWP Windows 10

查看:33
本文介绍了未检测到已安装的组件.无法解析 TargetName HighContrastBorder - UWP Windows 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

用户界面出现了一些尴尬的事情,也许与此有关,但我不知道是什么或为什么:

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

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

<CommandBar IsOpen="True"ClosedDisplayMode="紧凑"IsSticky="真"可见性="{绑定CommandBarViewModel.IsCommandBarVisible,转换器={StaticResource BoolToVisibilityConverter}}"Background="{ThemeResource SystemControlBackgroundAccentBrush}"><AppBarButton图标="添加"标签=添加"前景=白色"Command="{绑定 CommandBarViewModel.AddCommand}"可见性="{绑定 CommandBarViewModel.IsAddVisible,转换器={StaticResource BoolToVisibilityConverter}}"/><AppBarButton图标=刷新"标签=刷新"前景=白色"Command="{绑定 CommandBarViewModel.RefreshListCommand}"可见性="{绑定CommandBarViewModel.IsRefreshListVisible,转换器={StaticResource BoolToVisibilityConverter}}"/></CommandBar></Page.BottomAppBar>

没有 InnerException,异常是从 App.g.i.cs 抛出的

#if DEBUG &&!DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTIONUnhandledException += (sender, e) =>{如果(全局:: System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();};#万一

对我的问题(即文本截断和未处理的异常)有任何想法吗?

谢谢

更新 - 1:

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

 

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

System.Runtime.InteropServices.COMException"类型的异常发生在 GalaSoft.MvvmLight.dll 中,但未在用户代码中处理WinRT 信息:无法解析 TargetName HighContrastBorder.附加信息:未检测到已安装的组件.

如你所见,但它似乎来自 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;}

<代码>...\\相应地在应用程序的各个部分隐藏按钮.this.CommandBarViewModel.IsCancelVisible = false;

}

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

a) 能够在没有任何错误的情况下处理此问题.b) 能够正确地重绘"自身而无需切断文本.

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

更新 - 4:

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

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

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

无效的绑定路径CommandBarViewModel.IsCommandBarVisible":在AppShell"类型上找不到属性CommandBarViewModel"MyApp ..\MyApp\Views\AppShell.xaml


XAML 代码:

 <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="紧凑"IsSticky="{x:Bind CommandBarViewModel.IsCommandBarVisible}"Visibility="{x:Bind CommandBarViewModel.IsCommandBarVisible,转换器={StaticResource BoolToVisibilityConverter}}"背景="{ThemeResource SystemControlBackgroundAccentBrush}"IsEnabled="{x:Bind IsNotBusy}"><AppBarButton图标="添加"标签=添加"前景=白色"Command="{x:Bind CommandBarViewModel.RegisterCommand}"Visibility="{x:Bind CommandBarViewModel.IsRegisterVisible,转换器={StaticResource BoolToVisibilityConverter}}"/><AppBarButton图标=刷新"标签=刷新"前景=白色"Command="{x:Bind CommandBarViewModel.RefreshListCommand}"Visibility="{x:Bind CommandBarViewModel.IsRefreshListVisible,转换器={StaticResource BoolToVisibilityConverter}}"/></CommandBar></Page.BottomAppBar></页面>

谢谢.

解决方案

没有 InnerException,异常是从 App.g.i.cs 抛出的

#if DEBUG &&!DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTIONUnhandledException += (sender, e) =>{如果(全局:: System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();};#万一

当代码运行时 Add 按钮或 Refresh 按钮在最开始设置为不可见时,我可以重现此问题.

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

如果您首先将false"(不可见)设置为 IsAddVisibleIsRefreshListVisible,它不会生成匹配的 AppbarButton,使用 Binding 会发生错误.比如你用x:Bind设置Refresh按钮不可见,Add按钮可见,你会发现没有空格对于 CommandBar 中的 Refresh 按钮,Add 按钮将替换它.这可以证实我的观点,如果在初始化 Commandbar 时将 false 设置为 AppbarButton,它不会生成此按钮.

<块引用>

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

如果您检查

如你所见,它是CommandBarContentRoot中的一个Rectangle.

我无法重现此问题或文本截断问题,它们在我身边始终运行良好.我正在使用 MVVM,但我没有使用 MVVMLight 来测试问题.也许你可以分享你的样本.

My CommandBarhas its IsOpen property set to true in XAML and therefore the is text for each button is visible as I want the descriptions to remain visible.

When I click on ellipses button, it hides the text and the second time I click on it, I get the following error:

No installed components were detected. Cannot resolve TargetName HighContrastBorder.

There is something awkward going on with the UI and maybe it's related to this but I can't figure out what or why:

As you can see my buttons' text are cut-off for the various buttons I'm displaying:

Code wise, there's nothing special about it as far as I can see:

<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>

There is no InnerException and the exception is thrown from 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

Any ideas about both my issue i.e. text cut-off and unhandled exception?

Thanks

UPDATE - 1:

When I remove the binded property (CommandBarViewModel.IsCommandBarVisible) from the Visible property for the CommandBar and hardcode it to Visible, the error moves down the line and instead of occurring in the App.g.i.cs, it is now occurring binded property of the first button it is trying to set the visibility on i.e.

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

But this time I get the following error:

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.

Similar as you can see, but it seem to be coming from MVVMLight??? Makes no sense!

Any suggestions/ideas on how to resolve this?

UPDATE - 2:

If I remove all the Visibility properties (and their corresponding binding), the command is displayed accordingly (i.e. no more cut-off text) and I can click on the ellipses button over and over again and it no longer crashes!!

So it's definitely related to the Visibility and binding it to a property to the view model, but what exactly, I have no idea.

Could it be the ViewModel is only constructed when the page loads and at this stage it is too late for the CommandBar and it's buttons to be initialized correctly.

Odd as everything regarding showing/hidding buttons works as expected except that my text is cut-off and I can't click on the ellipses button or it crashes.

UPDATE - 3:

I found a work-around and I'm not jumping up and down about it as I feel it is wrong but for now it will do. In order to circumvent this error, I make sure that I set the command bar and buttons to visible when I initialize my ViewModel, then hide them accordingly based on the page it's on.

public class 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;

}

Personally I feel like it's a bug with the CommandBar control and buttons as I should be able to hide it (and its buttons) from the get go and it should

a) be able to handle this without any errors. b) be able to "redraw" itself correctly without having text-cut off.

I could be wrong of course and it could be something to do with my code, but from my perspective, removing the visibility binding fixes it and making it visible first fixes it, so it seems to be pointing down this way.

UPDATE - 4:

Here is the actual code. I've simplified it as much as I could (i.e. removed namespaces, DataTemplates, Main content, etc...), leaving just the CommandBar and its buttons. Hopefully this will help.

As you can see when using mvvmlight, my source is set to Locatorand my path is set to the relevant ViewModel, in this instance, AppShellViewModel.

Yet as explained to Grace, when I use x:bind instead of binding, I get the following error:

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


XAML Code:

    <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>

Thanks.

解决方案

There is no InnerException and the exception is thrown from 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

I can reproduce this problem when the Add button or the Refresh button is set to invisible at the very beginning when code is running.

To solve this problem, you can use x:Bind instead of Binding. {x:Bind} executes special-purpose code, which it generates at compile-time, and {Binding} uses general-purpose runtime object inspection.

If you set "false"(invisible) to the IsAddVisible or IsRefreshListVisible at first, it doesn't generate the matched AppbarButton, the error will happen using Binding. For example, you use x:Bind to set invisible to the Refresh Button and visible to the Add button, you will find there is no space for Refresh Button in the CommandBar, the Add button will replace the it. This can confirm my opinion, if you set false to the AppbarButton when the Commandbar is initialized, it doesn't generate this button.

No installed components were detected. Cannot resolve TargetName HighContrastBorder

If you check the template of CommandBar you will see there is a Rectangle named HighContrastBorder inside of the CommandBar.

Or you can use Live Visual Tree to find this HighContrastBorder when your code is running:

As you can see, it is a Rectangle in the ContentRoot of the CommandBar.

I can't reproduce either this problem, or the text cut-off problem, they works always fine by my side. I'm using MVVM, but I didn't use MVVMLight to test the problem. Maybe you can share your sample.

这篇关于未检测到已安装的组件.无法解析 TargetName HighContrastBorder - UWP Windows 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆