xaml - 为 UWP 应用实现 TeachingTip 控件
问题描述
要在我的 UWP 应用程序中安装TeachingTip -control,我已完成以下步骤:
Microsoft.UI.Xaml
在我的项目中通过 Nuget安装包- 添加
<XamlControlsResources xmlns = "using:Microsoft.UI.Xaml.Controls" />
到App.xaml
. - 导入的命名空间
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
我实现了TeachingTip -control 如下:
<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
如何<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
在我的 App.xaml 中正确添加资源?
解决方案
您的 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>
推荐阅读
- php - Laravel 5.8 重定向回来,消息未将消息传递到前端
- python - 如何使用 Python 修复 Pyx 模块中的回溯错误?
- python - 以散列形式将密码存储在 MySQL 数据库中 Django App
- powershell - Powershell 调用 -Command 带有空格的属性
- ios - SwiftUI:iPad 上不需要的拆分视图
- javascript - document.getElementById 重新调整不是在 vue.js 中动态更新,每次都返回 null
- css - 反应中的内联css不能动态工作
- excel - 合并不同工作表中的数据
- flask - 将列表传递给引导网格模板的有效方法
- c++ - 对象作为参数析构函数被调用但不是构造函数?