![](/img/trans.png)
[英]Is it possible to use both a converter AND a StringFormat in WPF MultiBinding?
[英]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
類型更改為DependencyProperty
( DependencyProperty.UnsetValue
)類型嗎?
如何在不讓元素按名稱綁定到自身的情況下實現通過Checked
屬性?
擺脫交互觸發器,並使用CheckBox
的Command
和CommandParameter
屬性:
<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.