2017-05-30 22 views
0

私は2つの列、NameTypeを持つXamGridを持っています。 Typeに応じて、私はNameのために別の種類の列を持ちたいので、私はTemplateColumnを使用しています。データテンプレートでは、ContentTemplateとを別の列スタイルに設定するDataTriggerという既定値を持つContentControlがあります(Typeが特定の値の場合)。 TemplateColumnの4つのテンプレート(ItemTemplateEditorTemplateAddNewRowItemTemplateAddNewRowEditorTemplate)をこのデータテンプレートに設定します。意図したとおりにXamGridのTemplateColumnのEditorTemplateが動作しない

ItemTemplateAddNewRowItemTemplateAddNewRowEditorTemplate仕事、しかしEditorTemplateは、添付の写真を参照していません。ここで

<code>ItemTemplate</code> and <code>AddNewRowItemTemplate</code>

<code>AddNewRowEditorTemplate</code>

<code>EditorTemplate</code>

を私のコードです:

MainWindow.xaml:

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:ig="http://schemas.infragistics.com/xaml" 
     Width="640" Height="480" > 
    <Window.Resources> 
     <DataTemplate x:Key="EditorTemplate"> 
      <TextBox Width="64"/> 
     </DataTemplate> 
     <DataTemplate x:Key="BoolEditorTemplate"> 
      <CheckBox/> 
     </DataTemplate> 
     <DataTemplate x:Key="DataTemplate"> 
      <ContentControl Content="{Binding }"> 
       <ContentControl.Style> 
        <Style TargetType="{x:Type ContentControl}"> 
         <Setter Property="ContentTemplate" Value="{StaticResource EditorTemplate}" /> 
         <Style.Triggers> 
          <DataTrigger Binding="{Binding Type}" Value="bool"> 
           <Setter Property="ContentTemplate" Value="{StaticResource BoolEditorTemplate}" /> 
          </DataTrigger> 
         </Style.Triggers> 
        </Style> 
       </ContentControl.Style> 
      </ContentControl> 
     </DataTemplate> 
    </Window.Resources> 
    <ig:XamGrid ItemsSource="{Binding DataCollection, RelativeSource={RelativeSource AncestorType=Window}}" 
       AutoGenerateColumns="False"> 
     <ig:XamGrid.EditingSettings> 
      <ig:EditingSettings AllowEditing="Row" /> 
     </ig:XamGrid.EditingSettings> 
     <ig:XamGrid.AddNewRowSettings> 
      <ig:AddNewRowSettings AllowAddNewRow="Top" /> 
     </ig:XamGrid.AddNewRowSettings> 

     <ig:XamGrid.Columns> 
      <ig:TemplateColumn Key="Name" 
           ItemTemplate="{StaticResource DataTemplate}" 
           AddNewRowItemTemplate="{StaticResource DataTemplate}" 
           EditorTemplate="{StaticResource DataTemplate}" 
           AddNewRowEditorTemplate="{StaticResource DataTemplate}"/> 
      <ig:TextColumn Key="Type"/> 
     </ig:XamGrid.Columns> 
    </ig:XamGrid> 
</Window> 

MainWindow.xaml.cs:

using System.Collections.ObjectModel; 

namespace WpfApplication1 
{ 
    public partial class MainWindow 
    { 
    public MainWindow() 
    { 
     InitializeComponent(); 
    } 

    public ObservableCollection<Data> DataCollection { get; } = new ObservableCollection<Data> 
    { 
     new Data { Name = "Foo", Type = "bool" }, 
     new Data { Name = "Bar", Type = "enum" } 
    }; 
    } 

    public class Data 
    { 
    public string Name { get; set; } 
    public string Type { get; set; } 
    } 
} 

答えて

0

としては、必要に応じEditorTemplateですが、またEditorStyleこのユースケースではないだけのために、here on the infragistics forumを説明しました。

<Style x:Key="EditorStyle" TargetType="{x:Type ContentControl}"> 
    <Setter Property="ContentTemplate" Value="{StaticResource EditorTemplate}" /> 
    <Style.Triggers> 
     <DataTrigger Binding="{Binding Type}" Value="bool"> 
      <Setter Property="ContentTemplate" Value="{StaticResource BoolEditorTemplate}" /> 
     </DataTrigger> 
    </Style.Triggers> 
</Style> 

<DataTemplate x:Key="DataTemplate"> 
    <ContentControl Content="{Binding }" 
        Style="{StaticResource EditorStyle}" />> 
</DataTemplate> 

[...] 

<ig:TemplateColumn Key="Name" 
        ItemTemplate="{StaticResource DataTemplate}" 
        AddNewRowItemTemplate="{StaticResource DataTemplate}" 
        EditorTemplate="{StaticResource DataTemplate}" 
        AddNewRowEditorTemplate="{StaticResource DataTemplate}" 
        EditorStyle="{StaticResource EditorStyle}" /> 
関連する問題