Reputation: 21
I want to know how to use the row index as a condition in the same way the column index is used in the code below:
<Style x:Key="DefaultDataGridCell" TargetType="{x:Type DataGridCell}">
<Setter Property="IsTabStop" Value="False" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Column.DisplayIndex}" Value="0" />
</MultiDataTrigger.Conditions>
<Setter Property="IsTabStop" Value="True" />
</MultiDataTrigger>
</Style.Triggers>
In this example the entire first column of the DataGrid is tabstop but I only need the first cell of the DataGrid to be tabstop. How can I do it?
Upvotes: 2
Views: 1198
Reputation: 169200
There is no property that you can bind to that returns the index of the row but the DataGridRow
class has a GetIndex()
method that you could call in a converter class:
namespace WpfApplication1
{
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (value as DataGridRow).GetIndex();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
<Style x:Key="DefaultDataGridCell" TargetType="{x:Type DataGridCell}"
xmlns:local="clr-namespace:WpfApplication1">
<Style.Resources>
<local:MyConverter x:Key="conv" />
</Style.Resources>
<Setter Property="IsTabStop" Value="False" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Column.DisplayIndex}" Value="0" />
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource conv}}" Value="0" />
</MultiDataTrigger.Conditions>
<Setter Property="IsTabStop" Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
You cannot bind directly to a method though so you will have to use a converter.
Upvotes: 2