为 UWP 应用实现教学提示控件 [英] Implementing TeachingTip control for a UWP App
问题描述
要安装
可能是什么问题?为什么我的代码不起作用?
我现在已经确定错误是由 App.xaml
引起的.在我安装 Nuget 包 Microsoft.UI.Xaml
后,预计会在 App.xaml
中添加以下代码:
但我已经在 App.xaml
中设置了其他设置和资源:
当我尝试仅在 App.xaml
中添加该行时,发生关键错误:
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
如果我给资源条目一个这样的键:
出现一个完全不同的错误:
Windows.UI.Xaml.Markup.XamlParseException:找不到此错误的文本.找不到名称为/Key TeachingTipBackgroundBrush 的资源
如何在 App.xaml 中正确添加资源 <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
?
您的 App.xaml 文件需要如下所示:
<资源字典><ResourceDictionary.MergedDictionaries><XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/></ResourceDictionary.MergedDictionaries><!-- 这里的其他样式--><Style TargetType="Button">...</风格></ResourceDictionary></Application.Resources>
To install the TeachingTip-control in my UWP app, I've done the following stepts:
- installed
Microsoft.UI.Xaml
package via Nuget in my project - Added
<XamlControlsResources xmlns = "using:Microsoft.UI.Xaml.Controls" />
intoApp.xaml
. - Imported Namespace
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
I implemented the TeachingTip-control as follows:
<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;
}
When I call the function I get the following DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
error (probably UI error), which I do not understand:
What could be the problem? Why does not my code work?
Edit:
I have now determined that the error is due to App.xaml
. After I've installed the Nuget package Microsoft.UI.Xaml
, it's expected to add the following code in App.xaml
:
But I have already in App.xaml
other settings and resources:
When I try to add only the line in App.xaml
a key error occurs:
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
If I give the resource entry a key like this:
<XamlControlsResources x: Key = "XamlControlsResources" xmlns = "using: Microsoft.UI.Xaml.Controls" />
It comes to a completely different error:
Windows.UI.Xaml.Markup.XamlParseException: "The text for this error is not found.
Can not find a Resource with the Name / Key TeachingTipBackgroundBrush
How can I properly add the resource <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
correctly in my App.xaml?
Your App.xaml file needs to look like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>
<!-- Other styles here -->
<Style TargetType="Button">
...
</Style>
</ResourceDictionary>
</Application.Resources>
这篇关于为 UWP 应用实现教学提示控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!