Change a Label's style and template in WPF
I change a Label's style and template as below:
<Label Content="Test">
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border BorderBrush="#DDD" BorderThickness="1" CornerRadius="2" Background="#EEE" Padding="4">
<!--<TextBlock Text="{TemplateBinding Content}" />-->
<ContentPresenter Content="{TemplateBinding开发者_如何学Python Content}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Label.Style>
</Label>
in design time, this works and design view shows all thing good, (with each TextBlock or ContentPresenter); but when I run the project (or compile it), receive this error:
Cannot find the static member 'ContentProperty' on the type 'Control'.
can anyone help me please? thanks a lot ):
Add TargetType="{x:Type Label}"
to the ControlTemplate (otherwise it won't "know" what properties are available).
精彩评论