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