2010-03-30 390 views
1

我發現代碼使用麪包屑代替我的頁面的導航按鈕。此代碼適用於將頁面設置爲啓動。我的問題是,我需要有一個窗口框架控制作爲啓動,這導致麪包屑根本不顯示。我似乎錯過了我的造型。這些類型曾經是NavigationWindow,但是我將它們改爲了Frame以嘗試獲得工作解決方案。WPF導航頁面Breadcrumb

<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

變化:

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

到:

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

其應該工作。