WPF Datagrid.Row AlternationIndex MultiTrigger Property and



我想知道为什么这不起作用:

<DataGrid AlternationCount="2"...
<DataGrid.RowStyle>
   <Style TargetType="{x:Type DataGridRow}">
      <Style.Triggers>
         <MultiTrigger>
           <MultiTrigger.Conditions>
              <Condition Binding="{Binding AlternationIndex, RelativeSource={RelativeSource Self}}" Value="0" />
              <Condition Binding="{Binding IsTicket}" Value="False" />
           </MultiTrigger.Conditions>
           <MultiTrigger.Setters>
              <Setter Property="Background" Value="White" />
            </MultiTrigger.Setters>
         </MultiTrigger>
      </Style.Triggers>
   </Style>
</DataGrid.RowStyle>

此代码抛出无效的exception"必须具有'属性'的非零值"。IStiket是DataContext的属性,该属性是

的DataGrid的

此代码有效,但我需要多怪:

<DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
            <Trigger Property="AlternationIndex" Value="0">
                <Setter Property="Background" Value="White" />
            </Trigger>
            <DataTrigger Binding="{Binding IsTicket}" Value="True">
               <DataTrigger.Setters>
                  <Setter Property="Background" Value="Gold" />
               </DataTrigger.Setters>
             </DataTrigger>
        </Style.Triggers>
    </Style>
 </DataGrid.RowStyle>

解决方案:语法错误,我必须使用MultidatatRigger:

<DataGrid.RowStyle>
   <Style TargetType="{x:Type DataGridRow}">
      <Style.Triggers>
         <MultiDataTrigger>
           <MultiDataTrigger.Conditions>
              <Condition Binding="{Binding AlternationIndex, RelativeSource={RelativeSource Self}}" Value="0" />
              <Condition Binding="{Binding IsTicket}" Value="False" />
           </MultiDataTrigger.Conditions>
           <MultiDataTrigger.Setters>
              <Setter Property="Background" Value="White" />
            </MultiDataTrigger.Setters>
         </MultiDataTrigger>
      </Style.Triggers>
   </Style>
</DataGrid.RowStyle>

您使用的是多触发器,而不是多尾rigger。尝试

<Style TargetType="{x:Type DataGridRow}">
    <Style.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Path=AlternationIndex, RelativeSource={RelativeSource Self}}" Value="0" />
                <Condition Binding="{Binding IsTicket}" Value="False" />
            </MultiDataTrigger.Conditions>
            <Setter Property="Background" Value="White" />
        </MultiDataTrigger>
    </Style.Triggers>
</Style>

相关内容

  • 没有找到相关文章

最新更新