2012-03-26 10 views
1

내 WPF 목록 상자에 대한 스타일을 정의했지만 직접 맨 위에 사각형을 추가하고 있습니다 ... 그 자체를 목록 상자 자체로 만드는 방법은 무엇입니까? enter image description hereListBox에 사각형 추가

스타일리스트 박스 나는 효과를 얻기 위해 현재해야 할 일은

<Style BasedOn="{StaticResource {x:Type ListBox}}" 
    TargetType="ListBox" 
    x:Key="PinnedList"> 
    <Setter Property="Background"> 
     <Setter.Value> 
      <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> 
       <LinearGradientBrush.GradientStops> 
        <GradientStop Offset="0.0" Color="#90DDDD" /> 
        <GradientStop Offset="1.0" Color="#5BFFFF" /> 
       </LinearGradientBrush.GradientStops> 
      </LinearGradientBrush> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListBox"> 
       <Border Name="Border" Background="{StaticResource WhiteSolid}" BorderBrush="{StaticResource GreatTeaHeaderBrush}" BorderThickness="4" CornerRadius="2"> 
        <ScrollViewer Margin="0" Focusable="false"> 
         <StackPanel Margin="2" IsItemsHost="True" /> 
        </ScrollViewer> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

(구형 : 그래서 현재 내가 최종 효과를 그 아래에 목록 상자를 추가 한 후 구형의 XAML을 작성하고 목록 상자) :

   <Rectangle Height="20" Width="20" Fill="{StaticResource GreenTeaBrush}" Margin="-7,37,129,0" VerticalAlignment="Top" x:Name="ui_recPinnedORGs"> 
       <Rectangle.LayoutTransform> 
        <RotateTransform Angle="-45"/> 
       </Rectangle.LayoutTransform> 
      </Rectangle> 
      <ListBox Style="{StaticResource PinnedList}" Height="Auto" MaxHeight="200" Visibility="Hidden" HorizontalAlignment="Left" Margin="-8,45,0,0" SelectionChanged="ui_lsbPinnedORGs_SelectionChanged" 
        SelectedItem="{Binding Path=SelectedPinnedORGsViewModel, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}" 
        SelectionMode="Single" ItemsSource="{Binding Path=ORGViewModels, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}" 
        ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" 
        VerticalAlignment="Top" Width="158" Name="ui_lsbPinnedORGs"> 
       <ListBox.ItemTemplate> 
        <HierarchicalDataTemplate> 
         <Label Content="{Binding Path=ORG.Acronym, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" /> 
        </HierarchicalDataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
+0

ListBoxItem (ListBox 아님)에 대한 스타일 시도 – Paparazzi

+0

감사합니다. Blam,하지만 아래 답변은 정상적으로 작동합니다. :) –

답변

1

ListBox 템플릿 스타일을 추출하면 수정할 수 있습니다. 예 :

<Page.Resources> 
    <SolidColorBrush x:Key="ListBorder" Color="#828790"/> 
    <Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}"> 
     <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> 
     <Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
     <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
     <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
     <Setter Property="ScrollViewer.CanContentScroll" Value="true"/> 
     <Setter Property="ScrollViewer.PanningMode" Value="Both"/> 
     <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListBox}"> 
        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true"> 
         <Grid> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="Auto"/> 
           <RowDefinition/> 
          </Grid.RowDefinitions> 
          <!-- here's a simple rectange --> 
          <Rectangle Height="5" Fill="Blue" /> 
          <ScrollViewer Grid.Row="1" Focusable="false" Padding="{TemplateBinding Padding}"> 
           <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
          </ScrollViewer> 
         </Grid> 
        </Border> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
         </Trigger> 
         <Trigger Property="IsGrouping" Value="true"> 
          <Setter Property="ScrollViewer.CanContentScroll" Value="false"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</Page.Resources> 

<Grid> 
    <ListBox Style="{DynamicResource ListBoxStyle1}"/> 
</Grid> 
관련 문제