我有一个绑定到视图模型中类的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>谢谢。
发布于 2013-05-26 15:53:21
您可能没有向项目中添加适当的绑定转换器(如代码示例中的静态资源mvc )。
幸运的是,这甚至不是必要的。您可以改为设置多绑定的StringFormat属性:
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1}">
<Binding Path="LastName"/>
<Binding Path="FirstName"/>
</MultiBinding>
</TextBlock.Text>https://stackoverflow.com/questions/16757178
复制相似问题