简体   繁体   English

Setter中无法识别或访问Path.Data属性

[英]Path.Data property not recognized or accesible in Setter

I am hosting a Path inside a Button and want to dynamically change the Data property based on the WindowState of the window that contains the control and thus I ended up with the following XAML code: 我在Button内托管一个Path并且想要基于包含控件的窗口的WindowState动态更改Data属性,因此最终得到以下XAML代码:

<Path SnapsToDevicePixels="True" Data="F1M0,0L0,9 9,9 9,0 0,0 0,3 8,3 8,8 1,8 1,3z"
    Fill="Black">
    <Path.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type system:Window}}, Path=WindowState}" Value="Maximized">
                    <Setter Property="Data" Value="F1M0,10L0,3 3,3 3,0 10,0 10,2 4,2 4,3 7,3 7,6 6,6 6,5 1,5 1,10z M1,10L7,10 7,7 10,7 10,2 9,2 9,6 6,6 6,9 1,9z" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Path.Style>
</Path>

Unfortunately I get the error message The member "Data" is not recognized or is not accesible. 不幸的是,我收到错误消息The member "Data" is not recognized or is not accesible. and I did not understand why this error occurs and neither was I able to find a workaround. 而且我不明白为什么会发生此错误,而且我也找不到解决方法。

you are missing TargetType . 您缺少TargetType

also note that if you set local value for Data , then a setter from trigger won't be able to change it, so you need a setter in a style 还需要注意的是,如果您为Data设置了本地值,那么触发器中的设置器将无法更改它,因此您需要使用样式设置器

<Path SnapsToDevicePixels="True" Fill="Black">
    <Path.Style>
        <Style TargetType="Path">
            <Setter Property="Data" Value="F1M0,0L0,9 9,9 9,0 0,0 0,3 8,3 8,8 1,8 1,3z"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type system:Window}}, Path=WindowState}" Value="Maximized">
                    <Setter Property="Data" Value="F1M0,10L0,3 3,3 3,0 10,0 10,2 4,2 4,3 7,3 7,6 6,6 6,5 1,5 1,10z M1,10L7,10 7,7 10,7 10,2 9,2 9,6 6,6 6,9 1,9z" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Path.Style>
</Path>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM