0

当我尝试使用 BorderThickness="0" BorderBrush="Transparent" 时,如何在 silverlight 中删除数据网格周围的边框,它会删除网格左右两侧和底部的 broder,但不是顶部我认为那是标题边框或但不确定我是否也删除了标题 HeadersVisibility="None" 如果有人可以提供帮助,那就太好了。

干杯

4

2 回答 2

1

您看到的元素是一个Rectangle被调用的ColumnHeadersAndRowsSeparator. 只需创建一个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>
于 2012-05-09T21:12:09.130 回答
1

在 Silverlight 2 Beta 2 中,生成的 DataGrid 被边框包围。不幸的是,无法通过简单地在 DataGrid 上设置一个属性来移除此边框。要删除它,需要覆盖 DataGrid 样式或“皮肤”的定义。

每个 Silverlight 控件 (FrameworkElement) 的外观在 ControlTemplate 中定义。使用样式,可以使用一组自定义 XAML 代码在您的应用程序中覆盖此模板。默认 XAML 定义可在 Silverlight 控件样式和模板文档中找到。特定于本主题,DataGrid 的 XAML 定义可在 DataGrid 样式和模板文档中找到。

在 DataGrid XAML 中,查找模板定义。一旦找到它,请注意 DataGrid 的 RootElement 被三个不同的 Border 元素包围。

这些元素很可能是需要删除的项目。要开始自定义,需要将 DataGrid 的样式 XAML 作为新资源添加到我们的应用程序中。我将把它直接添加到我的 UserControl,但它也可以添加到应用程序资源(在 App.xaml 中)。

要将 XAML 添加到 UserControl,请创建一个名为 UserControl.Resources 的新节点并将 DataGrid XAML 复制到其中(使用文档网页上方便的“复制代码”链接)。

DataGrid 和资源的命名空间定义必须匹配。在复制的 XAML 中,命名空间是 local:DataGrid。Visual Studio 工具生成的默认命名空间是 my:DataGrid。在上面的示例中,我将所有对 local 的引用更改为 my.

下一个需要注意的是 Style 必须有一个 Key。这用于将框架元素(我们的 DataGrid)映射到特定的样式定义。我已经为样式提供了 TestGrid 的键,它在以下 DataGrid 定义中使用。

此时,当您运行应用程序时,DataGrid 应该与之前完全相同(我们还没有更改任何内容)。

在我开始删除 Border 元素的定义之前,我想确保这些是罪魁祸首。为此,我要将它们的颜色更改为更明显的颜色。

运行应用程序,我得到一个屏幕

放大后,很明显这些元素如何参与 DataGrid 的显示。

从 XAML 中删除 Border 元素会生成所需的结果。

希望这不仅提供了如何从 DataGrid 中删除边框的参考,而且还提供了对自定义 Silverlight 控件可用可能性的快速介绍。

复制自:http ://devcenter.auburnrandall.com/Default.aspx?type=post&id=52

于 2012-05-09T11:21:12.027 回答