2012-05-09 2 views
0

BorderThickness = "0"을 시도하면 Silverlight에서 데이터 격자 주위의 테두리를 제거하는 방법 BorderBrush = "투명"오른쪽 아래에있는 브로 더를 제거합니다. 표 머리 그러나 나는 헤더 경계 또는 뭔가가 있다고 생각하지만 확실하지 않은 나는 또한 헤더를 제거했습니다 HeadersVisibility = "None" 누군가가 도울 수 있다면 좋을 것입니다.Silverlight에서 DataGrid 주위에 테두리를 제거하는 방법

건배 실버 라이트

답변

1

2 베타 2는 데이터 그리드 생성은 테두리로 둘러싸인 다. 불행하게도, DataGrid에 속성을 설정하기 만하면이 테두리를 제거 할 수 없습니다. 이를 제거하려면 DataGrid 스타일 또는 "스킨"의 정의를 재정의해야합니다.

각 Silverlight 컨트롤 (FrameworkElement)의 모양은 ControlTemplate 내에서 정의됩니다. 스타일을 사용하면 응용 프로그램 내에서이 템플리트를 사용자 정의 된 XAML 코드 세트로 대체 할 수 있습니다. 기본 XAML 정의는 Silverlight 컨트롤 스타일 및 서식 파일 설명서에서 볼 수 있습니다. 이 항목과 관련하여 DataGrid의 XAML 정의는 DataGrid 스타일 및 템플릿 설명서에 나와 있습니다.

DataGrid XAML에서 템플릿 정의를 찾습니다. 이 위치를 찾으면 DataGrid의 RootElement가 세 개의 별개 테두리 요소로 둘러싸여 있음을 알 수 있습니다.

이러한 요소는 제거해야하는 항목 일 가능성이 큽니다. 사용자 지정을 시작하려면 DataGrid의 XAML 스타일을 응용 프로그램에 새 리소스로 추가해야합니다. 이것을 직접 UserControl에 추가 하겠지만 App.xaml의 Application 리소스에도 추가 할 수 있습니다.

UserControl에 XAML을 추가하려면 UserControl.Resources라는 새 노드를 만들고 DataGrid XAML을 복사합니다 (설명서 웹 페이지의 편리한 "코드 복사"링크 사용).

DataGrid 및 리소스의 네임 스페이스 정의가 일치해야합니다. 복사 된 XAML에서 네임 스페이스는 로컬 : DataGrid입니다. Visual Studio 도구에서 생성되는 기본 네임 스페이스는 my : DataGrid입니다. 위의 예에서, local의 모든 참조를 my로 변경했습니다.

다음 항목은 스타일에 키가 있어야한다는 것입니다. 이것은 Framework 요소 (DataGrid)를 특정 스타일 정의에 매핑하는 데 사용됩니다. 스타일에 다음의 DataGrid 정의에서 사용되는 TestGrid의 키를 부여했습니다.

이 시점에서 응용 프로그램을 실행할 때 DataGrid는 이전과 똑같이 나타납니다 (아직 변경하지 않았습니다).

테두리 요소의 정의를 제거하기 전에 해당 요소가 범인인지 확인하고 싶습니다. 이렇게하려면 색상을 조금 더 분명하게 변경하겠습니다.

응용 프로그램을 실행, 나는의 확대는 A 화면

를 얻을 이러한 요소가 데이터 그리드의 표시에 참여하는 방법 명백하다.

XAML에서 테두리 요소를 제거하면 원하는 결과가 생성됩니다.

DataGrid에서 테두리를 제거하는 방법에 대한 참조를 제공 할뿐만 아니라 Silverlight 컨트롤을 사용자 지정하는 데 사용할 수있는 기능에 대해 간략하게 소개하기를 바랍니다.http://devcenter.auburnrandall.com/Default.aspx?type=post&id=52

+0

이전에 보았지만 그는 xaml 코드를 제공하지 않았고 이미지가 손상되었습니다. -_- – user1047278

1

요소 당신이 ColumnHeadersAndRowsSeparator라는 Rectangle입니다보고있다 :

는 복사. 그것없이 Style을 생성하십시오 :

<Style TargetType="sdk:DataGrid"> 
     <Setter Property="RowBackground" Value="#AAEAEFF4" /> 
     <Setter Property="AlternatingRowBackground" Value="#00FFFFFF" /> 
     <Setter Property="Background" Value="#FFFFFFFF" /> 
     <Setter Property="HeadersVisibility" Value="Column" /> 
     <Setter Property="HorizontalScrollBarVisibility" Value="Auto" /> 
     <Setter Property="VerticalScrollBarVisibility" Value="Auto" /> 
     <Setter Property="SelectionMode" Value="Extended" /> 
     <Setter Property="CanUserReorderColumns" Value="True" /> 
     <Setter Property="CanUserResizeColumns" Value="True" /> 
     <Setter Property="CanUserSortColumns" Value="True" /> 
     <Setter Property="AutoGenerateColumns" Value="True" /> 
     <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" /> 
     <Setter Property="BorderBrush"> 
      <Setter.Value> 
       <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
        <GradientStop Color="#FFA3AEB9" Offset="0"/> 
        <GradientStop Color="#FF8399A9" Offset="0.375"/> 
        <GradientStop Color="#FF718597" Offset="0.375"/> 
        <GradientStop Color="#FF617584" Offset="1"/> 
       </LinearGradientBrush> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="BorderThickness" Value="1" /> 
     <Setter Property="DragIndicatorStyle"> 
      <Setter.Value> 
       <!-- TODO: Change the TargetType to Control when the fix Jolt bugs 18719 is verified --> 
       <Style TargetType="ContentControl"> 
        <Setter Property="Foreground" Value="#7FFFFFFF" /> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <!-- TODO: Change the TargetType to Control when the fix Jolt bugs 18719 is verified --> 
          <ControlTemplate TargetType="ContentControl"> 
           <Grid> 
            <VisualStateManager.VisualStateGroups> 
             <VisualStateGroup x:Name="SortStates"> 
              <VisualState x:Name="Unsorted" /> 
              <VisualState x:Name="SortAscending"> 
               <Storyboard> 
                <DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0"/> 
               </Storyboard> 
              </VisualState> 
              <VisualState x:Name="SortDescending"> 
               <Storyboard> 
                <DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0"/> 
                <DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="(RenderTransform).ScaleY" Duration="0" To="-.9"/> 
               </Storyboard> 
              </VisualState> 
             </VisualStateGroup> 
            </VisualStateManager.VisualStateGroups> 

            <Rectangle x:Name="BackgroundRectangle" Stretch="Fill" Fill="#66808080" Grid.ColumnSpan="2" /> 

            <Rectangle x:Name="BackgroundGradient" Stretch="Fill" Grid.ColumnSpan="2" Opacity="0" > 
             <Rectangle.Fill> 
              <LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1"> 
               <GradientStop Color="#FFFFFFFF" Offset="0.015" /> 
               <GradientStop Color="#F9FFFFFF" Offset="0.375" /> 
               <GradientStop Color="#E5FFFFFF" Offset="0.6" /> 
               <GradientStop Color="#C6FFFFFF" Offset="1" /> 
              </LinearGradientBrush> 
             </Rectangle.Fill> 
            </Rectangle> 

            <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}"> 
             <Grid.ColumnDefinitions> 
              <ColumnDefinition/> 
              <ColumnDefinition Width="Auto" /> 
             </Grid.ColumnDefinitions> 

             <ContentPresenter Content="{TemplateBinding Content}"/> 

             <Path Grid.Column="1" Name="SortIcon" Fill="#7FFFFFFF" RenderTransformOrigin=".5,.5" HorizontalAlignment="Left" VerticalAlignment="Center" Opacity="0" Stretch="Uniform" Width="8" Margin="4,0,0,0" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z "> 
              <Path.RenderTransform> 
               <ScaleTransform ScaleX=".9" ScaleY=".9" /> 
              </Path.RenderTransform> 
             </Path> 
            </Grid> 
           </Grid> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="DropLocationIndicatorStyle"> 
      <Setter.Value> 
       <Style TargetType="ContentControl"> 
        <Setter Property="Background" Value="#FF3F4346"/> 
        <Setter Property="Width" Value="2"/> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="ContentControl"> 
           <Rectangle Fill="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"/> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="GridLinesVisibility" Value="Vertical" /> 
     <Setter Property="HorizontalGridLinesBrush" Value="#FFC9CACA" /> 
     <Setter Property="IsTabStop" Value="True" /> 
     <Setter Property="VerticalGridLinesBrush" Value="#FFC9CACA" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="sdk:DataGrid"> 
        <Grid> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal"/> 
           <VisualState x:Name="Disabled"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" Duration="0" To="1"/> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="2"> 
          <Grid Name="Root" Background="{TemplateBinding Background}"> 
           <Grid.Resources> 
            <!--Start: TopLeftHeaderTemplate--> 
            <ControlTemplate x:Key="TopLeftHeaderTemplate" TargetType="localprimitives:DataGridColumnHeader"> 
             <Grid Name="Root"> 
              <Grid.RowDefinitions> 
               <RowDefinition/> 
               <RowDefinition/> 
               <RowDefinition Height="Auto" /> 
              </Grid.RowDefinitions> 
              <Border BorderThickness="0,0,1,0" BorderBrush="#FFC9CACA" Background="#FF1F3B53" Grid.RowSpan="2"> 
               <Rectangle Stretch="Fill" StrokeThickness="1"> 
                <Rectangle.Fill> 
                 <LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1"> 
                  <GradientStop Color="#FCFFFFFF" Offset="0.015" /> 
                  <GradientStop Color="#F7FFFFFF" Offset="0.375" /> 
                  <GradientStop Color="#E5FFFFFF" Offset="0.6" /> 
                  <GradientStop Color="#D1FFFFFF" Offset="1" /> 
                 </LinearGradientBrush> 
                </Rectangle.Fill> 
               </Rectangle> 
              </Border> 
              <Rectangle VerticalAlignment="Bottom" Width="Auto" StrokeThickness="1" Height="1" Fill="#FFDBDCDC" Grid.RowSpan="2"/> 
             </Grid> 
            </ControlTemplate> 
            <!--End: TopLeftHeaderTemplate--> 

            <!--Start: TopRightHeaderTemplate--> 
            <ControlTemplate x:Key="TopRightHeaderTemplate" TargetType="localprimitives:DataGridColumnHeader"> 
             <Grid Name="RootElement"> 
              <Grid.RowDefinitions> 
               <RowDefinition/> 
               <RowDefinition/> 
               <RowDefinition Height="Auto" /> 
              </Grid.RowDefinitions> 
              <Border BorderThickness="1,0,0,0" BorderBrush="#FFC9CACA" Background="#FF1F3B53" Grid.RowSpan="2"> 
               <Rectangle Stretch="Fill"> 
                <Rectangle.Fill> 
                 <LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1"> 
                  <GradientStop Color="#FCFFFFFF" Offset="0.015" /> 
                  <GradientStop Color="#F7FFFFFF" Offset="0.375" /> 
                  <GradientStop Color="#E5FFFFFF" Offset="0.6" /> 
                  <GradientStop Color="#D1FFFFFF" Offset="1" /> 
                 </LinearGradientBrush> 
                </Rectangle.Fill> 
               </Rectangle> 
              </Border> 
             </Grid> 
            </ControlTemplate> 
            <!--End: TopRightHeaderTemplate--> 
           </Grid.Resources> 

           <Grid.RowDefinitions> 
            <RowDefinition Height="Auto" /> 
            <RowDefinition/> 
            <RowDefinition Height="Auto" /> 
            <RowDefinition Height="Auto" /> 
           </Grid.RowDefinitions> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="Auto" /> 
            <ColumnDefinition/> 
            <ColumnDefinition Width="Auto" /> 
           </Grid.ColumnDefinitions> 

           <localprimitives:DataGridColumnHeader Name="TopLeftCornerHeader" Template="{StaticResource TopLeftHeaderTemplate}" Width="22" /> 
           <localprimitives:DataGridColumnHeadersPresenter Name="ColumnHeadersPresenter" Grid.Column="1"/> 
           <localprimitives:DataGridColumnHeader Name="TopRightCornerHeader" Grid.Column="2" Template="{StaticResource TopRightHeaderTemplate}" /> 
           <!-- HERE IT IS THAT LINE YOU SEE -->                  
           <!--<Rectangle Name="ColumnHeadersAndRowsSeparator" Grid.ColumnSpan="3" VerticalAlignment="Bottom" Width="Auto" StrokeThickness="1" Height="1" Fill="#FFC9CACA"/>--> 

           <localprimitives:DataGridRowsPresenter Name="RowsPresenter" Grid.ColumnSpan="2" Grid.Row="1" /> 
           <Rectangle Name="BottomRightCorner" Fill="#FFE9EEF4" Grid.Column="2" Grid.Row="2" /> 
           <Rectangle Name="BottomLeftCorner" Fill="#FFE9EEF4" Grid.Row="2" Grid.ColumnSpan="2" /> 
           <ScrollBar Name="VerticalScrollbar" Orientation="Vertical" Grid.Column="2" Grid.Row="1" Width="18" Margin="0,-1,-1,-1"/> 

           <Grid Grid.Column="1" Grid.Row="2"> 
            <Grid.ColumnDefinitions> 
             <ColumnDefinition Width="Auto" /> 
             <ColumnDefinition/> 
            </Grid.ColumnDefinitions> 
            <Rectangle Name="FrozenColumnScrollBarSpacer" /> 
            <ScrollBar Name="HorizontalScrollbar" Grid.Column="1" Orientation="Horizontal" Height="18" Margin="-1,0,-1,-1"/> 
           </Grid> 

          </Grid> 
         </Border> 
         <Border x:Name="DisabledVisualElement" IsHitTestVisible="False" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" CornerRadius="2" Background="#8CFFFFFF" Opacity="0"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
관련 문제