1
嗨,我正在开发MVRlight的WinRT应用程序。我想要做的是用物品填充组合框,例如4种水果。我的SelectedItem应该是组合框绑定的第一种水果。这工作,但下一步是,我想使selectedIndex更改。例如,当第一种水果售罄时,SelectedIndex应该自动更改为我的Combobox集合中的第二个项目。将SelectedIndex绑定到不同的集合,然后收集项目源
所以,如果你想购买10块水果,你会得到10个组合框在你的屏幕上,你可以选择水果种类,当你选择了其中4个苹果,并且没有苹果了其他组合框的选定索引应改为第二种水果。
我知道这是一个令人困惑的问题。
基本上我需要的是能够将我的Selectedindex绑定到集合中与我的组合框不同的属性中。我会给你一点XAML的,希望能解释一点:
</ListView>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel IsHitTestVisible="{Binding HitTest}" Orientation="Horizontal">
<TextBlock Text="{Binding Day, Converter={StaticResource StringFormatConverter}, ConverterParameter='{}{0:dd MMM yyyy}' }"></TextBlock>
<ComboBox Width="196" ItemsSource="{Binding Path=FruitKind.FruitList, Source={StaticResource Locator}}" SelectedIndex="{Binding Path=FruitKind.FruitComboBoxItem, Source={StaticResource Locator}, ElementName={Binding Path=FruitIndex}}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding FruitKind}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我不知道这是可能的方式。 thnx
如何生成的组合框?您可以将所选项绑定到视图模型中的任何属性,并从任何函数内更改该值。 – 2013-03-20 17:05:11
组合框绑定到一个observablecollection,当我使用所选项目时,组合框在页面加载时保持空白 – Landvis 2013-03-20 19:17:03