WPF-ListBox-Tasten: wie ändern Sie auf ausgewählte Elemente klicken Sie mit XAML

Ich habe eine Vorlagen -ListBox:

<ListBox Grid.Row="0" Grid.Column="1" Background="Transparent" BorderThickness="0" x:Name="mainMenu"
    ItemsSource="{Binding Source={x:Static local:MenuConfig.MainMenu},  Mode=OneTime}"
   IsSynchronizedWithCurrentItem="True">
 <ListBox.ItemContainerStyle>
  <Style TargetType="ListBoxItem">
   <EventSetter Event="PreviewMouseUp" Handler="SelectCurrentItem"/>
  </Style>
 </ListBox.ItemContainerStyle>
 <ListBox.ItemsPanel>
  <ItemsPanelTemplate>
   <StackPanel Orientation="Horizontal"></StackPanel>
  </ItemsPanelTemplate>
 </ListBox.ItemsPanel>
  <ListBox.ItemTemplate>
  <DataTemplate>
   <Button>
    <StackPanel>
     <Image Source="{Binding Icon}" MaxHeight="32" MaxWidth="32"/>
     <TextBlock Text="{Binding Label}"/>
    </StackPanel>
   </Button>
  </DataTemplate>
 </ListBox.ItemTemplate>
</ListBox>

Das ausgewählte Element aktualisiert wird manuell mit code behind:

private void SelectCurrentItem(object sender, MouseButtonEventArgs e)
{
    ListBoxItem item = (ListBoxItem) sender;
    item.IsSelected = true;
}

Gibt es eine Möglichkeit, dies zu tun (update ausgewählte Element auf Schaltfläche klicken) mit XAML nur ?

InformationsquelleAutor Catalin DICU | 2010-02-03

Schreibe einen Kommentar