使用windows 's DataContext进行多绑定

本文关键字:绑定 DataContext windows 使用 | 更新日期: 2023-09-27 17:52:12

我试图根据窗口的Customer DependancyProperty是否为空来创建拖动装饰器。我在窗口的资源里有这个。绑定的第一部分是设置的(被拖动的项),但第二部分(窗口上的DependancyProperty)显示为UnsetValue。

这个属性在被用作窗口的数据上下文时被明确地初始化了。

<Window x:Name="root"
    ...
>
<Window.Resources>
    <DataTemplate x:Key="DragAdorner">
        <StackPanel Orientation="Horizontal">
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource vehicleDragConverter}">
                        <Binding/>
                        <Binding Path="Customer" ElementName="root"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </StackPanel>
</DataTemplate>

使用windows 's DataContext进行多绑定

customer不是元素window的直接属性。

  1. 使用<Binding Path="DataContext.Customer"..../>

或者你也可以在绑定中使用RelativeSource=FindControl Window