2017-03-02 18 views
2

Iは、列インデックスは、以下のコードで使用されるのと同じ方法で、条件として行インデックスを使用する方法を知りたい:この例ではWPF XAMLでDataGridCellスタイルのマルチトリガーで行インデックスを条件として使用する方法は?

<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> 

データグリッドの全体の最初の列タブストップですが、DataGridの最初のセルだけがタブトップになる必要があります。どうしたらいいですか?

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> 

答えて

0

は、あなたがそれに結合することができ、何のプロパティは、行のインデックスを返しませんが、DataGridRowクラスを使用すると、コンバータクラスで呼び出すことができGetIndex()方法がありますがありますメソッドに直接バインドすることはできませんが、コンバーターを使用する必要があります。

関連する問題