开发者

Change a Label's style and template in WPF

开发者 https://www.devze.com 2023-03-12 10:27 出处:网络
I change a Label\'s style and template as below: <Label Content=\"Test\"> <Label.Style> <Style TargetType=\"{x:Type Label}\">

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消