代码之家  ›  专栏  ›  技术社区  ›  Doug

WPF多重绑定转换器对象类型

  •  0
  • Doug  · 技术社区  · 7 年前

    我已经装订好了 Checked 方法的复选框事件。我还通过转换器(实现)将两个命令参数传递给该方法 IMultiValueConverter ). 在下面的代码中,两个 CommandParameter bool 和类型 string 分别地

    <CheckBox Name="cbTopLeftHeader" Content="Top Left Header"> 
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Checked">
                    <i:InvokeCommandAction Command="{Binding IncludeCheckedCommand}">
                        <i:InvokeCommandAction.CommandParameter>
                            <MultiBinding Converter="{StaticResource MultiBindingConverter}" ConverterParameter="IncludeChecked">
                                <Binding ElementName="cbTopLeftHeader" Path="IsChecked"></Binding>
                                <Binding Source="{StaticResource TopLeft}"></Binding>
                            </MultiBinding>
                        </i:InvokeCommandAction.CommandParameter>
                    </i:InvokeCommandAction>
                </i:EventTrigger>
            </i:Interaction.Triggers>
    </CheckBox>
    

    为什么如果我更换线路:

    <Binding ElementName="cbTopLeftHeader" Path="IsChecked"></Binding>
    

    <Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"></Binding>
    

    布尔 DependencyProperty ( DependencyProperty.UnsetValue )?

    选中的 属性,而不让元素按名称绑定到自身?

    1 回复  |  直到 7 年前
        1
  •  1
  •   mm8    7 年前

    去掉交互触发器并使用 Command CommandParameter CheckBox :

    <CheckBox Name="cbTopLeftHeader" Content="Top Left Header" Command="{Binding IncludeCheckedCommand}">
        <CheckBox.CommandParameter>
            <MultiBinding Converter="{StaticResource MultiBindingConverter}" ConverterParameter="IncludeChecked">
                <Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"/>
                <Binding Source="{StaticResource TopLeft}"></Binding>
            </MultiBinding>
        </CheckBox.CommandParameter>
    </CheckBox>
    

    或者坚持您当前的绑定方法 使用 ElementName {RelativeSource Self} InvokeCommandAction 复选框 .