1

I am using DataTrigger to change the DataTemplate based on a enum.

<TreeView >
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type model:Card}" ItemsSource="{Binding Reqs}">
            <StackPanel VerticalAlignment="Center">
                <TextBlock Text="{Binding Label}" FontWeight="Bold" Foreground="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Center" FontSize="15"/>
                <TextBlock Text="{Binding Reqs.Count}" FontWeight="UltraLight" Foreground="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Center" FontSize="10"/>
            </StackPanel>
        </HierarchicalDataTemplate>

        <DataTemplate DataType="{x:Type model:ReqCard}">
            <ContentControl>
                <ContentControl.Style>
                    <Style TargetType="{x:Type ContentControl}">
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate >
                                    <Border Width="340" Background="LightBlue">
                                        <Grid Name="PGrid" Margin="5">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Margin="2" Text="{Binding Label}" Foreground="Gray" FontSize="15" FontWeight="Normal"/>
                                            <CheckBox Grid.Column="1" Margin="2" IsChecked="{Binding IsMeet}" Click="IsMeet_OnClick"/>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding DemandType}" Value="{x:Static enums:DemandType.Condition}">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate >
                                            <Border Width="340" Background="LightBlue" >
                                                <Grid Name="KGrid" Margin="5">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="*"/>
                                                        <ColumnDefinition Width="Auto"/>
                                                    </Grid.ColumnDefinitions>
                                                    <TextBlock Margin="2" Text="{Binding Label}" Foreground="Gray" FontSize="15" FontWeight="Normal"/>
                                                    <TextBox Grid.Column="1" Width="20" Margin="2" Text="{Binding Condition}" Click="Condition_OnClick"/>
                                                </Grid>
                                            </Border>
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
        </DataTemplate>
    </TreeView.Resources>
</TreeView>

It displays no data.

Qiu
  • 5,651
  • 10
  • 49
  • 56
Halid
  • 448
  • 7
  • 16
  • Try taking a look at this SO on how to get the binding errors. http://stackoverflow.com/a/8850185/1808494 Without the rest of the code I can't psychically debug your code. – Aron Aug 16 '15 at 16:10
  • Without DataTrigger it works – Halid Aug 16 '15 at 17:19

0 Answers0