要在我的UWP应用中安装TeachingTip-控件,请执行以下步骤:
Microsoft.UI.Xaml
软件包<XamlControlsResources xmlns = "using:Microsoft.UI.Xaml.Controls" />
添加到了App.xaml
中。xmlns:controls="using:Microsoft.UI.Xaml.Controls"
我实现了 TeachingTip -控件,如下所示:
<Button x:Name="BackButton"
Background="{x:Null}"
Content="Back"
Click="BackButton_Click">
<Button.Resources>
<controls:TeachingTip x:Name="ToggleThemeTeachingTip"
Target="{x:Bind BackButton}"
Title="Change themes without hassle"
Subtitle="It's easier than ever to see control samples in both light and dark theme!"
CloseButtonContent="Got it!">
</controls:TeachingTip>
</Button.Resources>
</Button>
<Button x:Name="TeachingTipButton"
Click="TeachingTipButton_OnClick">
</Button>
private void TeachingTipButton_OnClick(object sender, RoutedEventArgs e)
{
ToggleThemeTeachingTip.IsOpen = true;
}
当我调用该函数时,出现以下DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
错误(可能是UI错误),我不理解:
可能是什么问题?为什么我的代码不起作用?
编辑:
我现在确定错误是由于App.xaml
引起的。我安装了Nuget软件包Microsoft.UI.Xaml
之后,应该在App.xaml
中添加以下代码:
当我尝试仅在App.xaml
中添加行时,会发生关键错误:
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
如果我给资源条目一个像这样的密钥:
<XamlControlsResources x: Key = "XamlControlsResources" xmlns = "using: Microsoft.UI.Xaml.Controls" />
这是一个完全不同的错误:
Windows.UI.Xaml.Markup.XamlParseException: "The text for this error is not found.
Can not find a Resource with the Name / Key TeachingTipBackgroundBrush
如何正确在App.xaml中正确添加资源<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
?
答案 0 :(得分:0)
我将您的代码粘贴到我的项目中,并且可以正常工作。但是,上面提供的代码没有触发按钮的内容,因此出现的唯一按钮是顶部按钮。您确定不会因为BackButton_Click
而不是TeachingTipButton_OnClick
中的代码而失败吗?
您可以从Microsoft.UI.Xaml.Controls
删除对Application.Resources
的重复引用
答案 1 :(得分:0)
我通过删除 ContentDialog Size样式和默认按钮样式解决了我的问题,使得<Application.Resources>
仅具有<XamlControlsResources x: Key = "XamlControlsResources" xmlns = "using: Microsoft.UI.Xaml.Controls" />
作为单个条目。就我而言,很遗憾,<Application.Resources> </Application.Resources>
中的多个条目未被接受。
答案 2 :(得分:0)
您的App.xaml文件需要如下所示:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>
<!-- Other styles here -->
<Style TargetType="Button">
...
</Style>
</ResourceDictionary>
</Application.Resources>