[英]The ControlTemplate is causing the following error “The property 'Content' is set more than once”
我只是第一次尝试将 ControlTemplate 用于我想要创建的按钮。
但是,只要我将标签<ControlTemplate>
放在任何地方,就会出现错误。
<Window x:Class="MAQButtonTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="695" Width="996">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Background="#FFE9F1F6"></Grid>
<Grid Grid.Column="1" Background="#FFD2E3ED">
</Grid>
</Grid>
<ControlTemplate></ControlTemplate>
</Window>
我应该把标签放在哪里才能不出现这个错误?
模板,如样式、画笔、数据模板都是资源,通常放置在您控件中的资源字典或资源部分中。
<Window>
<Window.Resources>
<ControlTemplate TargetType="{x:Type Button}"/>
<ControlTemplate x:Key="myTemplate" TargetType="{x:Type Button}"/>
<Window.Resources>
<!-- this will use your implicit defined template -->
<Button />
<!-- this will use your explicit defined template called myTemplate-->
<Button Template="{StaticResource myTemplate}"/>
</Window>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.