好吧,所以我有一个包含以下资源的窗口
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<TextBlock Text="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
我收到一条错误消息,说“会员”内容“无法识别或无法访问。” 我做错了什么?
答案 0 :(得分:11)
您必须在ControlTemplate上定义TargetType
<ControlTemplate TargetType="Button">
<Grid>
<TextBlock Text="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
答案 1 :(得分:2)
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<TextBlock Text="{TemplateBinding Button.Content}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
或
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<TextBlock Text="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>