代码之家  ›  专栏  ›  技术社区  ›  Eric

WPF折叠网格未设置样式

  •  0
  • Eric  · 技术社区  · 16 年前

    所以,我在列表框中有一个网格。其目的是,当选择listboxitem时,我希望显示网格,使所选项目展开以显示更多详细信息。我为此设置了一个样式触发器,效果很好,除了一件事:标签和文本块样式在网格上没有应用。

                <Style TargetType="{x:Type Grid}" x:Key="ListBoxItemCollapseGrid">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding 
                                            Path=IsSelected,
                                            RelativeSource=
                                            {
                                              RelativeSource 
                                              Mode=FindAncestor,
                                              AncestorType={x:Type ListBoxItem}
                                            }
                                          }"
                                 Value="False">
                        <Setter Property="Grid.Visibility" Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
                <Style.Resources>
                    <Style TargetType="{x:Type Label}">
                        <Setter Property="FontWeight" Value="Bold" />
                        <Setter Property="Foreground" Value="{StaticResource BaseText}" />
                        <Setter Property="Padding" Value="3,0,0,0" />
                    </Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="Foreground" Value="{StaticResource BaseText}" />
                    </Style>
                </Style.Resources>
            </Style>
    
    1 回复  |  直到 16 年前
        1
  •  0
  •   Eric    16 年前

    不管怎样,我的设计师在文件中放了两次这个样式,另一次它没有样式资源,它覆盖了我正在使用的样式。愚蠢的错误。

    推荐文章