Skip to content

RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Expander', AncestorLevel='1' #3891

@liuyafei518

Description

@liuyafei518

Bug explanation

why my app show bind error ?
this is Error description:
bindPath: ExpandDirection
target: RotateTransform.Angle
description: Unable to find resources: RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Expander', AncestorLevel='1'

this is my code :

<ListBox.ItemTemplate>
    <DataTemplate>
        <StackPanel
            HorizontalAlignment="Stretch"
            Background="Transparent"
            Orientation="Horizontal"
            PreviewMouseDown="StackPanel_PreviewMouseDown">
            <StackPanel
                Margin="25,10,0,10"
                Orientation="Horizontal"
                Visibility="{Binding IsShowParentMenu, Converter={StaticResource Boolean2VisibilityConverter}}">
                <materialDesign:PackIcon
                    Width="24"
                    Height="24"
                    Margin="0,0,5,0"
                    Foreground="White"
                    Kind="{Binding Icon}" />
                <TextBlock
                    Margin="10,0,10,0"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    FontSize="14"
                    FontWeight="Bold"
                    Foreground="White"
                    Text="{Binding Header}" />
            </StackPanel>
            <Expander
                x:Name="ExpanderMenu"
                Width="230"
                Margin="5,2,5,2"
                HorizontalAlignment="Center"
                Background="{x:Null}"
                ExpandDirection="Down"
                Foreground="White"
                IsExpanded="False"
                materialDesign:TransitionAssist.DisableTransitions="True"
                Visibility="{Binding HasChild, Converter={StaticResource Boolean2VisibilityConverter}}">

                <Expander.Header>
                    <StackPanel x:Name="ExpandHeader" Orientation="Horizontal">
                        <materialDesign:PackIcon
                            Width="24"
                            Height="24"
                            Margin="0,0,5,0"
                            Foreground="White"
                            Kind="{Binding Icon}" />
                        <TextBlock
                            Margin="10,0,10,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            FontSize="14"
                            FontWeight="Bold"
                            Foreground="White"
                            Text="{Binding Header}" />
                    </StackPanel>

                </Expander.Header>
                <ListView
                    x:Name="ListViewMenu"
                    Foreground="White"
                    ItemsSource="{Binding SubItems}"
                    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                    SelectionChanged="ListViewMenu_SelectionChanged">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel
                                x:Name="subItemPanel"
                                Margin="18,0,0,0"
                                Orientation="Horizontal">
                                <materialDesign:PackIcon
                                    Width="20"
                                    Height="20"
                                    Margin="0,0,10,0"
                                    VerticalAlignment="Center"
                                    Foreground="White"
                                    Kind="{Binding Icon}" />
                                <TextBlock
                                    Padding="5"
                                    VerticalAlignment="Center"
                                    FontSize="14"
                                    Text="{Binding Header}" />
                            </StackPanel>

                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Expander>
        </StackPanel>
    </DataTemplate>
</ListBox.ItemTemplate>

Version

5.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugevaluation requiredItems is pending review or evaluation by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions