RowHeaderTemplate和NewItemPlaceholder

时间:2015-09-29 19:32:39

标签: wpf templates datagrid

我正在尝试将图像显示或隐藏在rowHeader中。它适用于普通行,但对于NewItemPlaceHolder,它始终可见。我如何为NewItemPlaceHolder隐藏图像?

<DataGrid.RowHeaderTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="20" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Column="0" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                  AncestorType={x:Type DataGridRow}}, 
                                  Path=Item.xmlId}"/>
                        <Image Grid.Column="1"
                               Source="/MYAppli;component/Res/003_Fermer.png"
                               ToolTip="ERROR"
                               Margin="0"
                               Width="11" Height="11" 
                               >
                        <Image.Style>
                            <Style TargetType="{x:Type Image}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                  AncestorType={x:Type DataGridRow}}, 
                                  Path=Item.HasError}" Value="true" >
                                <Setter Property="Visibility"  Value="Visible" />
                            </DataTrigger>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                  AncestorType={x:Type DataGridRow}}, 
                                  Path=Item.HasError}" Value="false" >
                                        <Setter Property="Visibility"  Value="Hidden" />
                                    </DataTrigger>
                                </Style.Triggers>
                                </Style>
                        </Image.Style>
                    </Image>
                </Grid>
            </DataTemplate>

NewItemPlaceholder

1 个答案:

答案 0 :(得分:1)

最后我这样做:

        <Style x:Key="DataGridRowHeader" TargetType="DataGridRowHeader">
        <Setter Property="FontSize" Value="9" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding}" Value="{x:Static CollectionView.NewItemPlaceholder}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                            <Button Background="LightGray" IsEnabled="False">
                            <Image Source="/MYAppli;component/Res/031_Plus.png"
                                   Height="10"
                                   Width="10"></Image>
                            </Button>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>

NewItemPlaceHolder