WPF导航页面包屑

时间:2010-03-30 20:23:01

标签: wpf navigation breadcrumbs

我发现代码使用了面包屑而不是我的网页的导航按钮。此代码非常适合将页面设置为启动。我的问题是我需要一个带有框架控件的窗口作为启动,这导致面包屑根本不显示。我的造型似乎缺少一些东西。以前的类型是NavigationWindow,但我将它们更改为Frame以尝试获得可行的解决方案。

<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">
                                                    <Setter 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>

1 个答案:

答案 0 :(得分:1)

更改:

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

为:

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

它应该有用。