Название говорит все этоСтиль DataTrigger не оценки на начальной загрузки
<Page.Resources>
<local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<DataTemplate x:Key="level1">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="GroupTitle" FontSize="16" FontWeight="Bold" Foreground="#FF000532" Text="{Binding name}"/>
<TextBlock x:Name="GroupDescription" Text="{Binding description}"/>
<TextBlock x:Name="Depth" Text="{Binding childDepth}"/>
<ItemsControl ItemsSource="{Binding settings}">
</ItemsControl>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="level2">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="GroupTitle" FontSize="16" FontWeight="Bold" Foreground="#FF000532" Text="{Binding name}"/>
<TextBlock x:Name="GroupDescription" Text="{Binding description}"/>
<TextBlock x:Name="Depth" Text="{Binding childDepth}"/>
<ItemsControl ItemsSource="{Binding settings}">
</ItemsControl>
<TabControl ItemsSource="{Binding groups}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource level1}"/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid>
<ContentControl x:Name="SettingsDisplayer" Content="{Binding settingGroup, ElementName=page}">
<ContentControl.Resources>
<local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
</ContentControl.Resources>
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="ContentTemplate" Value="{StaticResource level1}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=childDepth}" Value="1">
<Setter Property="ContentTemplate" Value="{StaticResource level1}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=childDepth}" Value="2">
<Setter Property="ContentTemplate" Value="{StaticResource level2}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=childDepth}" Value="3">
<Setter Property="ContentTemplate" Value="{StaticResource level3}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=childDepth}" Value="4">
<Setter Property="ContentTemplate" Value="{StaticResource level4}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</Grid>
Поглотитель для childDepth
даже и не обращались, потому что я поставил консольный след там, чтобы знать, когда она есть. Свойство заселено, так как оно показывает правильную сумму, если смотреть на глубину TextBlock
в DataTemplate
.
Соответствующее свойство в моем классе:
public int childDepth { get { Console.WriteLine(this.getDepth()); return this.getDepth(); } }
Нет матер, что childDepth это Alwayse skipps спусковые и просто использует шаблон level1.
Похоже, у вас есть файл XML с более чем один корневым тегом. XML обычно имеет только один корневой тег, поэтому ваш xml является фрагментом. Вы можете обернуть данные xml в один корневой тег, используя метод string(): ваш текущий xml . string myString = "" + xml + " "; –
jdweng
@jdweng Что? нет, я не хочу. Это даже не компилируется. – Wobbles