2011-08-12 5 views
3

헤더가 있고 다양한 메뉴 항목이있는 글로벌 컨텍스트 메뉴 style/template이 필요합니다. 내 컨텍스트 메뉴의 메뉴 항목 수가 많아 질 수 있으므로 스크롤을 지원해야합니다.헤더와 스크롤바를 지원하는 컨텍스트 메뉴를 생성해야합니다.

내가 가진 현재 스타일의 문제점은 스크롤링을 지원하지 않는다는 것입니다. 메뉴 항목 수가 화면 크기를 초과하면 스크롤 막대가 표시되지 않습니다.

<Style 
    TargetType="{x:Type ContextMenu}" 
    x:Key="ContextMenuStyle"> 
    <Setter 
     Property="ContextMenu.Template"> 
     <Setter.Value> 
      <ControlTemplate> 
       <Border 
        BorderBrush="#868686" 
        BorderThickness="1" 
        Background="#FAFAFA"> 
        <StackPanel 
         Orientation="Vertical"> 
         <Label 
          Foreground="White" 
          Background="Blue"> 
          <Binding 
           RelativeSource= 
               "{RelativeSource AncestorType= 
               {x:Type ContextMenu}}" 
           Path="PlacementTarget.Tag" /> 
         </Label> 
         <Grid> 
          <Rectangle 
           Margin="1,1,1,1" 
           Width="25" 
           HorizontalAlignment="Left" 
           Fill="#E9EEEE" /> 
          <Rectangle 
           Margin="26,1,0,1" 
           Width="1" 
           HorizontalAlignment="Left" 
           Fill="#C5C5C5" /> 
          <Rectangle 
           Margin="27,1,0,1" 
           Width="1" 
           HorizontalAlignment="Left" 
           Fill="#FAFAFA" /> 
          <ScrollViewer 
           Margin="1,0,1,0" 
           Style="{DynamicResource 
             {ComponentResourceKey     
             ResourceId=MenuScrollViewer, 
             TypeInTargetAssembly= 
             {x:Type FrameworkElement}}}" 
           CanContentScroll="True" 
           Grid.ColumnSpan="2"> 
           <ItemsPresenter 
            KeyboardNavigation.DirectionalNavigation= 
            "Cycle" /> 
          </ScrollViewer> 
         </Grid> 
        </StackPanel> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

헤더 작품 위에 했나 스크롤 뷰어를 배치하지만 헤더는 또한 스크롤 -

여기 내가 사용하고 현재 스타일이다.

이것을 달성하는 가장 좋은 방법은 무엇입니까?

답변

2

이렇게 해보십시오. 두 개의 RowDefinitions (Auto, *)

<Style TargetType="{x:Type ContextMenu}"> 
    <Setter Property="ContextMenu.Template"> 
     <Setter.Value> 
      <ControlTemplate> 
       <Border BorderBrush="#868686" 
         BorderThickness="1" 
         Background="#FAFAFA"> 
        <Grid VerticalAlignment="Stretch"> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="*"/> 
         </Grid.RowDefinitions> 
         <Label Grid.Row="0" Foreground="White" Background="Blue"> 
          <Binding RelativeSource= "{RelativeSource AncestorType= {x:Type ContextMenu}}" Path="PlacementTarget.Tag" /> 
         </Label> 
         <Grid Grid.Row="1"> 
          <Rectangle Margin="1,1,1,1" 
             Width="25" 
             HorizontalAlignment="Left" 
             Fill="#E9EEEE" /> 
          <Rectangle Margin="26,1,0,1" 
             Width="1" 
             HorizontalAlignment="Left" 
             Fill="#C5C5C5" /> 
          <Rectangle Margin="27,1,0,1" 
             Width="1" 
             HorizontalAlignment="Left" 
             Fill="#FAFAFA" /> 
          <ScrollViewer Margin="1,0,1,0" 
              Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" 
              CanContentScroll="True" 
              Grid.ColumnSpan="2"> 
           <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle" /> 
          </ScrollViewer> 
         </Grid> 
        </Grid> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

감사 Meleak을 dockpanel 당신의 StackPanel에 교체 , 당신 말이 맞아요. 나는 이미 이것을 시도하고 작동하지만 그것은 나를위한 가능한 해결책이 아니다; 높이를 고정하지 않고 해결책을 찾고 있습니다. – akjoshi

+0

@akjoshi : 좋습니다. 스크롤링은 언제 활성화되어야합니까? 스크린 바깥 쪽? –

+0

예, 메뉴 항목 수가 화면에 맞지 않을 때마다; 그냥 장소에 대한 명확한 상황에 맞는 메뉴를 만들 때 (실행시 생성되는) 엄청난 수의 항목으로 구성 될 수 있습니다. – akjoshi

1

으로 그리드에 수직 StackPanel을 (높이를 제한하지 않는) 변경하면이 시도 :

<Border> 
     <DockPanel> 
      <Label DockPanel.Dock="Top">Label</Label> 
      <ScrollViewer> 
       ....  
      </ScrollViewer> 
     </DockPanel> 
    </Border> 

간단히

+0

고맙습니다. objectbox는 이것을 시도하고 어떻게 진행되는지 알려줍니다 ... – akjoshi

관련 문제