簡體   English   中英

WPF MultiBinding Converter對象類型

[英]WPF MultiBinding Converter Object Type

我已經將復選框的Checked事件綁定到方法。 我還通過轉換器將兩個Command Parameters傳遞給該方法(實現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>

在我的轉換器中,IsChecked參數從bool類型更改為DependencyPropertyDependencyProperty.UnsetValue )類型嗎?

如何在不讓元素按名稱綁定到自身的情況下實現通過Checked屬性?

擺脫交互觸發器,並使用CheckBoxCommandCommandParameter屬性:

<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綁定到CheckBox當前方法。 InvokeCommandAction {RelativeSource Self}不是CheckBox

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM