2012-03-28 7 views
1

Noch lernen WPF .... danke für jede Hilfe.ListView DataTemplate, ControlTemplate und Style

Gibt es eine Möglichkeit, dies zu Umgestalten:

<ListBox Name="lbEvents" 
       VerticalAlignment="Stretch" 
       SelectionMode="Multiple" 
       Loaded="lbCenterEvents_Loaded" 
       HorizontalAlignment="Stretch" 
       BorderBrush="Transparent" 
       Background="Transparent" 
       SelectionChanged="lbCenterEvents_SelectionChanged" 
       ItemContainerStyle="{StaticResource KioskCheckboxListItemContainer}"> 
      <ListBox.Resources> 
       <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /> 
       <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" /> 
       <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" /> 
      </ListBox.Resources> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <CheckBox Grid.Column="0" 
         Margin="0,10,0,0" 
         Padding="5,30,5,10" 
         DockPanel.Dock="Top" 
         Style="{StaticResource KioskCheckBox}" 
         Background="{StaticResource brshSecondaryColor}" 
         FontSize="26" 
         HorizontalAlignment="Stretch" 
         IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" 
         Content="{Binding DisplayDescriptionForKiosk}"> 
        </CheckBox> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 

in so etwas wie folgt aus:

<ListBox Name="lbEvents" Style="{StaticResource MyFinalListBox}" 
       VerticalAlignment="Stretch" 
       SelectionMode="Multiple" 
       Loaded="lbCenterEvents_Loaded" 
       HorizontalAlignment="Stretch" 
       BorderBrush="Transparent" 
       Background="Transparent" /> 

Ich versuche nur, um eine Vorstellung zu bekommen ... Ich sollte nicht genau brauchen Code, Pseudocode sollte ausreichen (ich hoffe), danke im Voraus.

EDIT: Ich frage dies, weil ich versuche, einen Weg zu finden, dies mit der geringsten Anzahl von Verweisen auf StaticResources zu tun. Ich weiß, dass ich die Vorlagen und Stile herausziehen kann, aber ich hoffe, dass mir jemand zeigen kann, wie man es auf eine StaticResource reduziert.

+0

Für Arten, die Sie wollen auf alle ListBoxs Stil verwenden Target = "{x: Typ ListViewItem}"> in App.xaml – Paparazzi

Antwort

0

Ja, Sie wollen (so etwas wie)

<UserControl> 
    <UserControl.Resources> 
     <DataTemplate x:Key="MyItemTemplate" DataType="{x:Type MyDataType}"> 
      <CheckBox Grid.Column="0" 
       Margin="0,10,0,0" 
       Padding="5,30,5,10" 
       DockPanel.Dock="Top" 
       Style="{StaticResource KioskCheckBox}" 
       Background="{StaticResource brshSecondaryColor}" 
       FontSize="26" 
       HorizontalAlignment="Stretch" 
       IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" 
       Content="{Binding DisplayDescriptionForKiosk}"> 
      </CheckBox> 
     </DataTemplate> 
     <Style x:Key="MyFinalListBox" TargetType="{x:Type ListBox}"> 
      <Setter Property="SelectionMode" Value="Multiple" /> 
      ... put more properties here 
     </Style> 
    </UserControl.Resources> 
</UserControl> 

<ListBox Name="lbEvents" 
     ItemTemplate="{StaticResource MyItemTemplate}" 
     Style="{StaticResource MyFinalListBox}" 
     VerticalAlignment="Stretch" 
     Loaded="lbCenterEvents_Loaded" 
     HorizontalAlignment="Stretch" 
     BorderBrush="Transparent" 
     Background="Transparent" />