3

グループ化およびソートされた PagedCollectionView にバインドしている DataGrid があります。1 つの列にクリック可能なリンクが含まれていますが、DataGrid の内容は編集できません。

DataGrid の SelectionMode を、DataGridSelectionMode.Single複数行の選択を停止するように制限しました。ただし、選択された行には、選択された行の残りの部分よりもわずかに明るい色で描画され、境界線を持つ選択されたセルもあります。

基本的に、SelectedRow は必要ですが、SelectedCell は必要ありません(UI/表示の観点から)。

プロパティを設定するのは簡単なことのように感じますが、DataGrids テンプレートを編集したり、VisualStateManager をいじったりする必要があるのではないかと感じています。

DataGrid 以外の別のコントロールに切り替えてよかったのですが、グループ化を表示できるようにする必要があります。

4

2 に答える 2

6

個々のセルが選択されていないように見えるようにする「a」方法を見つけましたが、それが最善の方法かどうかはわかりません。
DataGrid の CellStyle を編集し、FocusVisual という名前の Rectangle を見つけます。これは、選択されたセルを示すために使用される Rectangle です。Fill & Stroke を透明に設定し、StrokeThickness も 0 に設定します。Rectangle を完全に削除しないでください。他のものは Rectangle がそこにあることを期待しているためです。xaml は次のようになります。

    <Style x:Key="NonSelectableDataGridCellStyle" TargetType="data:DataGridCell">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="data:DataGridCell">
                    <Grid x:Name="Root" Background="{TemplateBinding Background}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CurrentStates">
                                <VisualState x:Name="Regular"/>
                                <VisualState x:Name="Current">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" 
                                            Storyboard.TargetName="FocusVisual" 
                                            Storyboard.TargetProperty="Opacity" To="1"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ValidationStates">
                                <VisualState x:Name="Valid"/>
                                <VisualState x:Name="Invalid">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="InvalidVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <ColorAnimation Duration="0" Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="(Fill).Color" To="#FFFFFFFF"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle x:Name="FocusVisual" 
                            Fill="Transparent"
                            Stroke="Transparent"
                            StrokeThickness="0" 
                            HorizontalAlignment="Stretch" 
                            VerticalAlignment="Stretch" 
                            IsHitTestVisible="false" 
                            Opacity="0"
                                   />
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                        <Rectangle x:Name="InvalidVisualElement" Stroke="#FFDC000C" StrokeThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHitTestVisible="False" Opacity="0"/>
                        <Rectangle x:Name="RightGridLine" VerticalAlignment="Stretch" Width="1" Grid.Column="1"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

CellStyle を DataGrid に追加します。

<data:DataGrid x:Name="uiDataGrid" 
           CellStyle="{StaticResource NonSelectableDataGridCellStyle}"
           >
     ...
</data:DataGrid>
于 2009-10-30T05:01:45.580 に答える
2

「見えない」列を追加することもできます:

    <sdk:DataGrid.Columns>
    <sdk:DataGridTextColumn Binding="{Binding Path=Nothing}" MinWidth="0" MaxWidth="0" />

そして、現在のセルが変更されるたびに現在のセルにします:

Private Sub _CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.CurrentCellChanged
    If Me.CurrentColumn IsNot Nothing Then Me.CurrentColumn = Me.Columns(0)
End Sub

これは私にぴったりでした。

于 2010-09-13T21:00:37.143 に答える