阅读背景:

样式DataTrigger不评估初始加载

来源:互联网 

Title says it all

标题说明了一切

<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>
<Page.Resources>



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: