2012-11-13 2 views
0

모두 안녕하세요!Xaml TabControl 창 상단에

그림에 표시된 xaml-markup 디자인에 문제가 있습니다. 탭 항목 헤더가있는 한 줄에 창 단추를 배치하는 방법 TAB1, TAB2, TAB3?

http://dl.dropbox.com/u/59774606/so_question_pic.png

내가 좋아하는 윈도우 버튼에 대한 사용자 지정 컨트롤을 사용

<Border> 
    <StackPanel Orientation="Horizontal"> 
     ... buttons ... 
    </StackPanel> 
</Border> 

사람이 내가 이것을 어떻게 구현할 수있는 아이디어가 있습니까?

답변

1

아마도 창 테두리를 제거하고 직접 단추를 그려야 할 것입니다. 버튼 클릭을 직접 처리해야합니다 (최대화가 창을 최대화 할 때 복원하는 것도 잊지 마세요). 창을 직접 드래그 할 수도 있습니다.

enter image description here

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:WpfApplication1" 
     Title="" WindowStyle="None" AllowsTransparency="True" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}"   
     > 
    <Grid> 
     <Grid Background="Silver"> 
      <TabControl> 
       <TabItem Header="Tab 1"/> 
       <TabItem Header="Tab 2"/> 
       <TabItem Header="Tab 3"/>     
      </TabControl> 
     </Grid> 
     <StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal" > 
      <Button Content="_" Width="30" Command="{Binding MinimizeCommand}"/> 
      <Button Content="-" Width="30" Command="{Binding MaximizeCommand}" /> 
      <Button Content="x" Width="30" Command="{Binding CloseCommand}"/> 
     </StackPanel>   
    </Grid> 
</Window> 

당신이 버튼에 매여 볼 수있는 명령

가 창에 뒤에 코드에 정의되어 있습니다. 당신은 제목 표시 줄 영역으로 이동 탭, WPF에서 멋진 유리 창문을 그릴 할 수있는 WPF Shell Integration library라고 마이크로 소프트에서 지금 소멸 프로젝트는이

public partial class MainWindow : Window 
    { 
     public ICommand CloseCommand 
     { 
      get { return (ICommand)GetValue(CloseCommandProperty); } 
      set { SetValue(CloseCommandProperty, value); } 
     } 
     public ICommand MinimizeCommand 
     { 
      get { return (ICommand)GetValue(MinimizeCommandProperty); } 
      set { SetValue(MinimizeCommandProperty, value); } 
     } 
     public ICommand MaximizeCommand 
     { 
      get { return (ICommand)GetValue(MaximizeCommandProperty); } 
      set { SetValue(MaximizeCommandProperty, value); } 
     } 

     public static readonly DependencyProperty CloseCommandProperty = DependencyProperty.Register("CloseCommand", typeof(ICommand), typeof(MainWindow), new PropertyMetadata(null)); 
     public static readonly DependencyProperty MinimizeCommandProperty = DependencyProperty.Register("MinimizeCommand", typeof(ICommand), typeof(MainWindow), new PropertyMetadata(null)); 
     public static readonly DependencyProperty MaximizeCommandProperty = DependencyProperty.Register("MaximizeCommand", typeof(ICommand), typeof(MainWindow), new PropertyMetadata(null)); 

     public MainWindow() 
     { 
      InitializeComponent(); 
      System.Windows.Interactivity.EventObserver a; 


      // Setup the commands. 
      CloseCommand = new RoutedCommand("CloseCommand", typeof(MainWindow)); 
      MinimizeCommand = new RoutedCommand("MinimizeCommand", typeof(MainWindow)); 
      MaximizeCommand = new RoutedCommand("MaximizeCommand", typeof(MainWindow)); 

      // Put them in the windows command bindings. 
      this.CommandBindings.Add(new CommandBinding(CloseCommand, new ExecutedRoutedEventHandler((s, e) => this.Close()), new CanExecuteRoutedEventHandler((s, e) => { e.CanExecute = true; }))); 
      this.CommandBindings.Add(new CommandBinding(MinimizeCommand, new ExecutedRoutedEventHandler((s, e) => this.WindowState = System.Windows.WindowState.Minimized), new CanExecuteRoutedEventHandler((s, e) => { e.CanExecute = true; }))); 
      this.CommandBindings.Add(new CommandBinding(MaximizeCommand, new ExecutedRoutedEventHandler((s, e) => this.WindowState = System.Windows.WindowState.Maximized), new CanExecuteRoutedEventHandler((s, e) => { e.CanExecute = true; }))); 
     } 

     protected override void OnMouseMove(MouseEventArgs e) 
     { 
      if (e.LeftButton == MouseButtonState.Pressed) 
       DragMove(); 

      base.OnMouseMove(e); 
     } 
} 
+0

+1, 왜냐하면 명령 대신 클릭 이벤트를 사용하여 창 관리 코드를 처리하기 때문입니다. – Rachel

+0

mvvm을 살펴볼 때까지는 UI가 어떻게 보이는지 알지 못합니다. – Andy

+0

UI 용 코드 만 제공하는 MVVM의 코드 숨김을 사용하면 문제가 없으며 비즈니스/응용 프로그램 논리가 없습니다. 나는 UI를 UI에 맞게 조작하는 것을 고려할 것이다. MVVM을 사용할 때 코드 숨김에 넣는 것이 좋다. :) – Rachel

0

. 불행히도 완벽하게 작동하지 않습니다.

WPF SDK 용 Microsoft 리본에는 최신 버전이 포함되어 있습니다. 이것은 RibbonWindow가 Office처럼 제목 막대 영역에 리본을 병합하는 방법입니다.