Страница навигации WPF - PullRequest
       7

Страница навигации WPF

1 голос
/ 31 марта 2010

Я нашел код для использования хлебных крошек вместо кнопок навигации для моих страниц. Этот код прекрасно работает с настройкой страницы в качестве запуска. Моя проблема в том, что мне нужно иметь окно с управлением кадрами в качестве запуска, и это приводит к тому, что крошка не отображается вообще. Кажется, я что-то упускаю из-за моего стиля. Раньше типы были 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 Ответ

1 голос
/ 24 июня 2010

Изменение:

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

до:

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

и это должно работать.

...