gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:10:11 25 4
gpt4 key购买 nike

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

当我单击省略号按钮时,它会隐藏文本,第二次单击它时,出现以下错误:
No installed components were detected. Cannot resolve 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:

当我从 CommandBarViewModel.IsCommandBarVisible 中删除绑定(bind)属性 ( Visible ) CommandBar 的属性并将其硬编码为 Visible ,错误向下移动,而不是发生在 App.g.i.cs 中,它现在正在发生它试图设置可见性的第一个按钮的绑定(bind)属性,即
        <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:

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

所以它肯定与 Visibility 相关,并将其绑定(bind)到 View 模型的属性,但具体是什么,我不知道。

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

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

更新 - 3:

我找到了一种解决方法,我不会在它上面跳来跳去,因为我觉得它是错误的,但现在它会做。为了避免这个错误,我确保在初始化 ViewModel 时将命令栏和按钮设置为可见,然后根据它所在的页面相应地隐藏它们。

公共(public)类 AppShellViewModel
{
公共(public)无效 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)能够正确地“重绘”自身而无需切断文本。

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

更新 - 4:

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

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

然而,正如向 Grace 解释的那样,当我使用 x:bind 而不是绑定(bind)时,我收到以下错误:
Invalid binding path 'CommandBarViewModel.IsCommandBarVisible' :
Property 'CommandBarViewModel' can't be found on type 'AppShell'
MyApp ..\MyApp\Views\AppShell.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>

谢谢。

最佳答案

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

xml:

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

xml.cs:

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

我无法重现您的异常和 UI 错误,这是我的猜测:在您的项目中某处,您提到了 HighContrastBorder作为风格的目标。我建议您在其他地方找到并修复它,您发布的代码正在运行。我的构建是 14316 桌面。

更新

我加 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值,可见性相应更新。

关于xaml - 未检测到已安装的组件。无法解析 TargetName HighContrastBorder - UWP Windows 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36573000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com