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 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 ):
The most common way to declare a style is as a resource in the Resources section in a XAML file. Because styles are resources, they obey the same scoping rules that apply to all resources. Put simply, where you declare a style affects where the style can be applied.
A template describes the overall look and visual appearance of a control. For each control, there is a default template associated with it which gives the control its appearance.
There are four types of templates: ControlTemplate. DataTemplate. ItemsPanelTemplate.
The ControlTemplate allows you to specify the visual structure of a control. The control author can define the default ControlTemplate and the application author can override the ControlTemplate to reconstruct the visual structure of the control.
Add TargetType="{x:Type Label}"
to the ControlTemplate (otherwise it won't "know" what properties are available).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With