我试图改变绑定列表框中的项目的选定状态,基于如果在项目绑定到的类中使用对象,我似乎无法发现做这件事的方式,它具有保持活力,因为对象可能会改变,因此在类的不同实例中使用:更改绑定列表框中的项目的选定状态
<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