![](/img/trans.png)
[英]C# WPF How to use custom ComboBox item property in MultiBinding
[英]how to use multibinding in the text property in a listBox?
我有一個列表框綁定到我的視圖模型中的類。 此類具有許多屬性,但我想在我的listBox中顯示其中兩個。
我看那個例子( post )
主要代碼是這樣的:
<ListBox ItemsSource="{Binding PersonList}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource mvc}"
ConverterParameter=", ">
<Binding Path="LastName"/>
<Binding Path="FirstName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的問題是,當我嘗試使用它時,在我的axml中不可用。 因此,我無法繼續執行代碼。
為什么我不提供多重綁定?
我的axml是:
<ListBox HorizontalAlignment="Stretch" Margin="5,41,0,0" Name="lsbPersonas" VerticalAlignment="Stretch" Grid.Row="1"
ItemsSource="{Binding Personas}"
SelectionMode="Extended" Height="112">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<Multibinding ???? (I don't have this avaliable)
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
謝謝。
您可能尚未在項目中添加適當的綁定轉換器(例如代碼示例中的靜態資源mvc
)。
幸運的是,它甚至沒有必要。 您可以改為設置MultiBinding的StringFormat
屬性:
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1}">
<Binding Path="LastName"/>
<Binding Path="FirstName"/>
</MultiBinding>
</TextBlock.Text>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.