2015-09-29 40 views
0

我試圖把一個圖像可見或隱藏在rowHeader中。它正常工作,但對於NewItemPlaceHolder它始終可見。我如何隱藏NewItemPlaceHolder的圖像?RowHeaderTemplate和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

+0

在這裏你可以找到樣本,如何再整它http://stackoverflow.com/a/20651622/1979354 – Spawn

+0

如何訪問我的圖片代碼? – Frederic7391

回答

0

最後我這樣做如下:

 <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