开发者

Problem setting specific member of CornerRadius in style setter

开发者 https://www.devze.com 2023-03-31 14:06 出处:网络
In the Resources section of a ControlTemplate I try to use a setter in a DataTrigger to modify individual corner radii on a Border:

In the Resources section of a ControlTemplate I try to use a setter in a DataTrigger to modify individual corner radii on a Border:

<Style x:Key="SectionBorder" TargetType="{x:Type Border}" >
    <Setter Property="CornerRadius" Value="5" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding HasChildSection, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
            <Setter Property="(Border.CornerRadius).(CornerRadius.BottomLeft)" Value="0" />
            <Setter Property="(Border.CornerRadius).(CornerRadius.BottomRight)" Value="0" />                                    
        </DataTrigger>
    </Style.Triggers>
</Style>

This generates the compiler error:

"Cannot resolve the Style Property 'BottomLeft)'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property."

Is WPF getting confused because CornerRadius is both property name and type name? Or am I not using "Class.Property syntax" properly? If I just use "CornerRadius.BottomLeft" for Property, I get a XamlParseException at runtime, 开发者_如何转开发stating that Property cannot be set to null.


That is not how setters work, you cannot set properties of properties, you only can replace the whole CornerRadius with a new one.

Property expects one property not a property path.

0

精彩评论

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

关注公众号