xaml - 在 XAML UWP 中使用另一个文件夹中的字典
问题描述
这是我的字典 [Dictionaries/myDictionary.xaml] 的内容:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:myApp/Dictionaries"
xmlns:media="using:Windows.UI.Xaml.Media">
<ResourceDictionary x:Key="Default">
<AcrylicBrush x:Key="myAcrylicBrush"
BackgroundSource="HostBackdrop"
TintColor="#202020"
TintOpacity="0.8"
FallbackColor="#202020"/>
</ResourceDictionary>
</ResourceDictionary>
这里是我需要使用它的地方 [Pages/myPage]:
<Page
x:Class="myApp.Pages.myPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:myApp.Pages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Here it gives me error -->
<ResourceDictionary Source="pack://application:,,,/ReferencedAssembly;component/Dictionaries/myDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="myStyle" TargetType="Grid">
<Setter Property="Background" Value="{StaticResource myAcrylicBrush}"/>
</Style>
</ResourceDictionary>
</Page.Resources>
<Grid x:Name="gridPrincipale" Style="{StaticResource myStyle}">
</Grid>
</Page>
我试过了
Source="pack://application:,,,/ReferencedAssembly;component/Dictionaries/myDictionary.xaml"
但它不起作用……</p>
文件夹“Dictionaries”和“Pages”都在项目的文件夹中。
解决方案
对于 UWP,您需要使用源的ms-appx
位置。
例子:
<ResourceDictionary Source="ms-appx:///Company.Themes/Dictionaries/myDictionary.xaml" />
Company.Themes
项目名称在哪里,是项目Dictionaries/myDictionary.xaml
根目录下资源文件的位置
推荐阅读
- arguments - 使用 argparse 多个位置参数并使其中一个“可选”包含在输入中
- django - 如何修复循环导入?
- c# - KeyDown 防止文本出现在 TextBox [UWP] 中
- ethereum - Web3.js:从合约方法执行中获取返回值
- struct - 朱莉娅:避免许多函数参数的有效而整洁的方法
- python - 如何在 TensorFlow 对象检测库中恢复更详细的指标?
- yandex - 在 clickhouse 中获取单个字节。无法获得非常简单的查询工作
- c++ - 用于对象构造的 C++ 模板函数
- reactjs - ReactJS 事件 - this.props.onSubmit(this.state....)
- python - Django CMS 通过 pip 修改已安装应用程序的插件