开发者

Problem setting specific member of CornerRadius in style setter

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜