我試圖改變綁定列表框中的項目的選定狀態,基於如果在項目綁定到的類中使用對象,我似乎無法發現做這件事的方式,它具有保持活力,因爲對象可能會改變,因此在類的不同實例中使用:更改綁定列表框中的項目的選定狀態
<Popup x:Name="ContextMenuPopup" Height="250" Width="300" Margin="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Canvas Name="popupholder" Background="DarkSeaGreen" Height="250" Width="300" HorizontalAlignment="Center">
<StackPanel Orientation="Vertical">
<TextBlock Name="popupTitle" Text="Select Investments" Margin="20,0,0,0" FontFamily="Courier New" FontSize="22" HorizontalAlignment="Center" Foreground="Black" />
<ListBox x:Name="investPicker" SelectionChanged="ListBox_SelectionChanged" LayoutUpdated="investPicker_LayoutUpdated" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="10,20,0,0" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Width="100"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Name="executeSelection" Content="Ok" Click="executeSelection_Click" Margin="40,5,0,0" VerticalAlignment="Bottom"/>
</StackPanel>
</Canvas>
</Popup>
Thwe後面的代碼是:
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
this.investPicker.ItemsSource = storedInvestments;
foreach (Investment investment in investPicker.Items)
{
foreach (CardDataSet card in investment.attachedCards)
if (card.ID == activeCard.ID)
VisualStateManager.GoToState((ListBoxItem) investPicker.Items[investment.ID -1], "Selected", true);
}
ContextMenuPopup.IsOpen = true;
}
現在很明顯的代碼不起作用從我的類到ListBoxItem的無效投射,任何人都知道我可以如何這個?
作品像做夢一樣,非常感謝你,我仍然在這個新的,所以我不知道我=>實際上做了,但我加了一些解釋性的東西上,它的工作原理:) – Phil 2012-07-11 13:24:00
,希望它有助於! – Rytmis 2012-07-12 10:09:07