【发布时间】:2021-01-27 17:32:58
【问题描述】:
我想创建一个模板化控件,并且对于我的“共享”项目,我使用了“添加新项”对话框来创建一个默认的模板化控件。这会构建,但当然,它还没有在我的项目中使用。
如何在我的主页中引用它?我看到很多示例,但没有一个可以找到,解释如何设置命名空间。
它创建了 Themes\Generic.xaml 和 TitlebarTemplate.cs(后者是我为模板选择的名称)。
这是我的 Generic.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UnoTest.Shared">
<Style TargetType="local:TitlebarTemplate" >
...
</Style>
</ResourceDictionary>
还有,这是一个非常简洁的主页:
<Page
x:Class="UnoTest.ListPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UnoTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
...
</Grid.RowDefinitions>
... put template here ...
</Grid>
</Page>
我需要添加什么命名空间来引用模板?并且,请包括实际引用它的语法。
我正在为 Uno 平台执行此操作,但我认为语法与 UWP 相同。
编辑
我把这个放在我的页面上:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
但我仍然找不到引用 TitlebarTemplate 的方法。
【问题讨论】:
-
确实有必要像您一样在 Uno 中显式引用
Generic.xaml字典(尽管它在 UWP 中自动完成)。但是,在那之后,它应该表现正确。您能否确认您当前的代码在 UWP 中正常工作?
标签: templates uwp uno-platform