2016-02-26 110 views
1

我擁有Metro UI的WPF應用程序。主窗口全屏打開。它的上面我有MenuLinkGroup這看起來是這樣的:WPF Metro UI - LinkGroup水平滾動問題

<mui:ModernWindow.MenuLinkGroups> 
     <mui:LinkGroup DisplayName="FirstGroup"> 
      <mui:LinkGroup.Links> 
       <mui:Link DisplayName="Very long description" Source=""/> 
       <mui:Link DisplayName="Very long description" Source=""/> 
      </mui:LinkGroup.Links> 
     </mui:LinkGroup> 
     <mui:LinkGroup DisplayName="SecondGroup"> 
      <mui:LinkGroup.Links> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
      </mui:LinkGroup.Links> 
     </mui:LinkGroup> 
     <mui:LinkGroup DisplayName="ThirdGroup"> 
      <mui:LinkGroup.Links> 
       <mui:Link DisplayName="Very long description" Source="" /> 
       <mui:Link DisplayName="Very long description" Source="" /> 
      </mui:LinkGroup.Links> 
     </mui:LinkGroup> 
</mui:ModernWindow.MenuLinkGroups> 

主要問題是,惠蔭用戶有小顯示器,比他不能來看看所有的名字從SecondGroup,而且他也無法伊斯利導航tchem鼠標光標。

我的問題:是否有任何放置一些滾動或mayby包裝,屏幕太小?

回答

1

要修復FirstFloor.ModernUI中菜單的佈局,您需要爲ModernMenu控件編寫新的wpf樣式以覆蓋默認佈局。默認樣式代碼可以在項目github頁面https://github.com/firstfloorsoftware/mui/blob/master/1.0/FirstFloor.ModernUI/Shared/Themes/ModernMenu.xaml上找到。在您的應用程序,例如在App.xaml中添加引用ModernMenu類的命名空間:

xmlns:firstfloor="clr-namespace:FirstFloor.ModernUI.Windows.Controls;assembly=FirstFloor.ModernUI" 

然後在資源定義新的默認樣式:

<Style TargetType="firstfloor:ModernMenu"></Style> 

的關鍵點改變而自動換菜單將2個列表框從StackPanel改變爲WrapPanel並設置屬性ScrollViewer.Horizo​​ntalScrollBarVisibility =「Disabled」。這些變化後,你的風格應該是這樣的:

<Style TargetType="firstfloor:ModernMenu"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="firstfloor:ModernMenu"> 
       <Grid> 
        <Grid.Resources> 
         <Style TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}"> 
          <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/> 
          <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/> 
          <Setter Property="ScrollViewer.CanContentScroll" Value="false"/> 
          <Setter Property="ScrollViewer.PanningMode" Value="Both"/> 
         </Style> 
        </Grid.Resources> 

        <Grid.RowDefinitions> 
         <RowDefinition /> 
         <RowDefinition /> 
        </Grid.RowDefinitions> 

        <ListBox ItemsSource="{TemplateBinding VisibleLinkGroups}" 
          ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
          SelectedItem="{Binding SelectedLinkGroup, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"> 
         <ListBox.ItemContainerStyle> 
          <Style TargetType="ListBoxItem"> 
           <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
           <Setter Property="FontFamily" Value="Segoe UI Light" /> 
           <Setter Property="Foreground" Value="{DynamicResource MenuText}" /> 
           <Setter Property="FontSize" Value="23"/> 
           <Setter Property="HorizontalContentAlignment" Value="Center" /> 
           <Setter Property="VerticalContentAlignment" Value="Center" /> 
           <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" /> 
           <Setter Property="Margin" Value="0,0,12,0" /> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="ListBoxItem"> 
              <TextBlock DataContext="{TemplateBinding Content}" 
                 Text="{Binding DisplayName, Converter={StaticResource ToLowerConverter}}" 
                 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                 VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
              <ControlTemplate.Triggers> 
               <Trigger Property="IsMouseOver" Value="true"> 
                <Setter Property="Foreground" Value="{DynamicResource MenuTextHover}"/> 
               </Trigger> 
               <Trigger Property="IsSelected" Value="true"> 
                <Setter Property="Foreground" Value="{DynamicResource MenuTextSelected}"/> 
               </Trigger> 
              </ControlTemplate.Triggers> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
          </Style> 
         </ListBox.ItemContainerStyle> 
         <ListBox.ItemsPanel> 
          <ItemsPanelTemplate> 
           <WrapPanel Orientation="Horizontal" /> 
          </ItemsPanelTemplate> 
         </ListBox.ItemsPanel> 
        </ListBox> 

        <ListBox Grid.Row="1" 
          ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
          ItemsSource="{Binding SelectedLinkGroup.Links, RelativeSource={RelativeSource TemplatedParent}}" 
          SelectedItem="{Binding SelectedLink, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" 
          VerticalAlignment="Top"> 
         <ListBox.ItemContainerStyle> 
          <Style TargetType="ListBoxItem"> 
           <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
           <Setter Property="FontFamily" Value="Segoe UI" /> 
           <Setter Property="Foreground" Value="{DynamicResource SubMenuText}" /> 
           <Setter Property="FontSize" Value="11"/> 
           <Setter Property="Margin" Value="0,0,12,0" /> 
           <Setter Property="HorizontalContentAlignment" Value="Center" /> 
           <Setter Property="VerticalContentAlignment" Value="Center" /> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="ListBoxItem"> 
              <Grid DataContext="{TemplateBinding Content}" 
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"> 
               <TextBlock Text="{Binding DisplayName, Converter={StaticResource ToUpperConverter}}" TextAlignment="Center"/> 
               <TextBlock Text="{Binding DisplayName, Converter={StaticResource ToUpperConverter}}" FontWeight="Bold" Visibility="Hidden" /> 
              </Grid> 

              <ControlTemplate.Triggers> 
               <Trigger Property="IsMouseOver" Value="true"> 
                <Setter Property="Foreground" Value="{DynamicResource SubMenuTextHover}"/> 
               </Trigger> 
               <Trigger Property="IsSelected" Value="true"> 
                <Setter Property="Foreground" Value="{DynamicResource SubMenuTextSelected}"/> 
                <Setter Property="FontWeight" Value="Bold" /> 
               </Trigger> 
              </ControlTemplate.Triggers> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
          </Style> 
         </ListBox.ItemContainerStyle> 
         <ListBox.ItemsPanel> 
          <ItemsPanelTemplate> 
           <WrapPanel Orientation="Horizontal" /> 
          </ItemsPanelTemplate> 
         </ListBox.ItemsPanel> 
        </ListBox> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

工程就像一個魅力!點給你 – Marcin