繁体   English   中英

将转换器分配给祖先成员以在XAML中进行绑定

[英]Assign a converter to a member of ancestor for binding in xaml

我想知道如何将转换器分配给祖先Viewport名为ConvertPoint的成员?

<DataTemplate DataType="{x:Type local:TestShape}">
    <DataTemplate.Resources>
        <RelativeSource AncestorType="{x:Type root:Viewport}" x:Key="Viewport"/>
        <root:BezierScaleConvertor x:Key="BezierScaleConvertor" />
    </DataTemplate.Resources>
    <control:TestShape>
        <control:TestShape.StartPoint>
            <MultiBinding Converter="???"> <----------- Here I don't know how to refer to the member ConvertPoint which is a convertor in Viewport, if I use dynamicResource or Binding, it will raise an exception because it's not a DP.
                <Binding Path="StartPoint" />
                <Binding Path="ScaleX" RelativeSource="{StaticResource Viewport}"/>
                <Binding Path="ScaleY" RelativeSource="{StaticResource Viewport}" />
            </MultiBinding>
        </control:TestShape.StartPoint>
        <control:TestShape.Segments>
            <MultiBinding Converter="{StaticResource BezierScaleConvertor}">
                <Binding Path="Segments" />
                <Binding Path="ScaleX" RelativeSource="{StaticResource Viewport}" />
                <Binding Path="ScaleY" RelativeSource="{StaticResource Viewport}" />
            </MultiBinding>
        </control:TestShape.Segments>
    </control:TestShape>
</DataTemplate>

我终于明白了。

要100%使此cas起作用,您应该使用c#代码版本的datatemplate。

就这样。

暂无
暂无

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

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