2009-07-23 64 views
4

有沒有辦法在WPF GridView上設置垂直邊框?WPF的GridView是否有垂直邊框?

以下工作適用於一些漂亮的水平邊框。有沒有一種好的方法可以將垂直邊框添加到位於此ListView內的GridView中?

<Style x:Key="ListViewItemBase" TargetType="{x:Type ListViewItem}"> 
    <Setter Property="BorderThickness" Value="1" /> 
    <Setter Property="BorderBrush" Value="#BABABE" /> 
</Style> 

在此先感謝

回答

2

試試這個...從http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/12/16/wpf-listview-vertical-lines-horizontal-as-bonus.aspx

<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" 
      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"            
      ContentTemplate="{TemplateBinding ContentTemplate}" 
      KeyboardNavigation.DirectionalNavigation="Local" 
      CanContentScroll="{TemplateBinding CanContentScroll}"> 

    <ScrollContentPresenter.Content> 
     <Grid> 
      <!-- Container of vertical and horizontal lines --> 
      <ItemsControl Margin="3,0,0,0" 
          ItemsSource="{Binding Path=TemplatedParent.View.Columns, 
             RelativeSource={RelativeSource TemplatedParent}}"> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 
         <Border Width="{Binding Path=ActualWidth}" 
           BorderThickness="0,0,1,0" 
           BorderBrush="{DynamicResource verticalLineColor}" /> 
        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <StackPanel Orientation="Horizontal" /> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 

       <!-- Fill background with horizontal lines --> 
       <ItemsControl.Background> 
        <VisualBrush TileMode="Tile" 
           Stretch="None" 
           Viewport="{Binding Source={StaticResource columnHeight}, 
              Converter={StaticResource columnViewportConverter}}" 
           ViewportUnits="Absolute"> 
         <VisualBrush.Visual> 
          <StackPanel HorizontalAlignment="Stretch" 
             VerticalAlignment="Stretch"> 
           <!-- Add Rectangles here for more horizontal lines --> 
           <Rectangle Height="{DynamicResource columnHeight}" 
              VerticalAlignment="Stretch" 
              Fill="{DynamicResource horizontalLineColor1}" 
              Width="1" /> 
           <Rectangle Height="{DynamicResource columnHeight}" 
              VerticalAlignment="Stretch" 
              Fill="{DynamicResource horizontalLineColor2}" 
              Width="1" /> 
          </StackPanel> 
         </VisualBrush.Visual> 
        </VisualBrush> 
       </ItemsControl.Background>   
      </ItemsControl> 
      <ContentControl Content="{TemplateBinding Content}" /> 
     </Grid> 
    </ScrollContentPresenter.Content>           
</ScrollContentPresenter>