4
나는 DataGrid
이며 선택한 행과 포커스가있는 행을 동기화하려고합니다. 즉, 집중된 행이 변경된 경우 선택한 행이 변경되고 선택된 행이 변경되면 포커스가있는 행이됩니다.DataGridRow 포커스 및 선택 항목을 동기화 된 상태로 유지하는 방법?
다음 XAML이 포함 된 WPF 창에서 포커스가있는 행과 선택한 행을 어떻게 동기화 할 수 있습니까? 나는 이것이 기본 동작입니다 생각으로 다음과 같은 이미지로
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<x:Array x:Key="MyList" Type="sys:String" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String>Hello</sys:String>
<sys:String>World</sys:String>
<sys:String>World</sys:String>
<sys:String>World</sys:String>
<sys:String>World</sys:String>
<sys:String>World</sys:String>
<sys:String>World</sys:String>
<sys:String>World</sys:String>
<sys:String>World</sys:String>
</x:Array>
<Style TargetType="{x:Type DataGrid}">
<Setter Property="AlternationCount" Value="2" />
<Setter Property="AutoGenerateColumns" Value="False"/>
</Style>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Focusable" Value="False"/>
</Style>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Focusable" Value="True"/>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="AlternationIndex" Value="0"/>
<Condition Property="IsSelected" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="White"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="AlternationIndex" Value="1"/>
<Condition Property="IsSelected" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Gainsboro"/>
</MultiTrigger>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="Gainsboro"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#BF228B22"/>
<Setter Property="BorderBrush" Value="ForestGreen"/>
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<DataGrid ItemsSource="{StaticResource MyList}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding}" Width="*"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
, 당신은 빨간색으로 포커스 사각형과 녹색에서 선택한 행이 명확하게 동기화되지 않은 것을 볼 수 있습니다. 내가 원했던 것은 항상 동일한 것입니다. 즉, SelectedRow는 항상 Focused이고 FocusedRow는 항상 Selected입니다.
감사합니다. 나는 이것을 곧 시도 할 것이다. 나는이 길을 시작하고 있었지만 먼저 물어볼 것이라고 생각했다. – Jim