开发者

WPF Navigation Page Breadcrumb

开发者 https://www.devze.com 2022-12-25 07:36 出处:网络
I found code to use a breadcrumb instead of the navigation buttons for my pages.This code works perfect with setting a page as the startup.My problem is that I need to have a window with a frame contr

I found code to use a breadcrumb instead of the navigation buttons for my pages. This code works perfect with setting a page as the startup. My problem is that I need to have a window with a frame control as the startup and this is causing the breadcrumb to not show at all. I seem to be missing something with my styling. The types used to be NavigationWindow but I changed them to Frame to try and get a working solution.

<Style TargetType="Frame" x:Key="{x:Type Frame}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Frame">
                <Grid Background="Transparent">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <ItemsControl ItemsSource="{Binding 
                        RelativeSource={RelativeSource AncestorType={x:Type Frame}}, 
                        Path=BackStack}">

                        <!--Force the ItemsContol to use a wrap panel as Items host-->
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <local:InverseWrapPanel KeyboardNavigation.TabNavigation="Cycle"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>

                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Button Command="NavigationCommands.NavigateJournal"
                                        CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
                                        Content="{Binding Name}">
                                    <Button.Template>
                                        <ControlTemplate TargetType="Button">
                                            <WrapPanel>
                                                <TextBlock Name="text1" FontWeight="Bold" Text="{TemplateBinding Content}"/>
                                                <TextBlock Name="text2" FontWeight="Bold" Text=">>" Margin="2,0,0,0"/>
                                            </WrapPanel>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Sett开发者_StackOverflower TargetName="text1" Property="Foreground" Value="Blue"/>
                                                    <Setter TargetName="text2" Property="Foreground" Value="Blue"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>

                    </ItemsControl>

                    <AdornerDecorator Grid.Row="2">
                        <ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/>
                    </AdornerDecorator>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


Change:

<ItemsControl ItemsSource="{Binding 
                        RelativeSource={RelativeSource AncestorType={x:Type Frame}}, 
                        Path=BackStack}">

to:

<ItemsControl ItemsSource="{Binding 
                        RelativeSource={RelativeSource TemplatedParent}, 
                        Path=BackStack}">

and its should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消