2013-03-21 2 views
1

좋아요, 그래서 탭 컨트롤 템플릿을 수정하여 두 개의 버튼을 추가했습니다. 하나는 열리고 다른 하나는 다른 탭과 함께 저장됩니다.WPF OnMouse 템플릿에서 위로

내가해야 할 일은 버튼이 창 내부에있는 OpenSave/CloseSave 기능을 실행하도록하는 것입니다. 각각의 윈도우는 윈도우에서 함수를 사용해야하는 이유가 무엇인지에 따라 다른 방식으로 자신 만의 열기 및 저장 기능을 갖게됩니다.

<Style x:Key="EditorTabControl" TargetType="{x:Type TabControl}"> 
    <Setter Property="SnapsToDevicePixels" Value="True" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TabControl}"> 
       <Grid SnapsToDevicePixels="True"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="0" /> 
         <RowDefinition Height="auto" /> 
        </Grid.RowDefinitions> 
        <Border Grid.Row="2" Panel.ZIndex="1" Background="#fafafa" Padding="10" BorderBrush="#ededed" BorderThickness="0 1 0 0"> 
         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> 
          <Button Content="Open" Style="{StaticResource EditorButtonStyle}"/> 
          <Button Content="Save" Style="{StaticResource EditorButtonStyle}"/> 
          <TabPanel IsItemsHost="True"/> 
         </StackPanel> 
        </Border> 
        <Border Grid.Row="0" BorderThickness="0" BorderBrush="#696969" Background="#FFF"> 
         <ContentPresenter Content="{TemplateBinding SelectedContent}" /> 
        </Border> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

그렇다면 제어 템플릿이 사용되는 창에있는 함수를 실행하게하려면 어떻게해야합니까?

+0

귀하의 질문은 ...이 같은 창을 가질 수 있습니까? – David

+0

그렇다면 컨트롤 템플릿이 사용되는 창에있는 함수를 실행하게하려면 어떻게해야합니까? –

+0

'ICommand'바인딩이 작동하지 않습니까? –

답변

0

명령 및 바인딩을 사용하여이 작업을 수행 할 수 있습니다. 주 창에서 저장 및 닫기 명령을 설정 한 다음 연결 만들기를 위해 RelativeSource를 사용할 수 있습니다.

public partial class MainWindow : Window 
{ 


    public MainWindow() 
    { 
     InitializeComponent(); 
    } 

    public ICommand Open { get; set; } //Need to implement, maybe could be a RelayCommand or DelegateCommand, you may search in the internet 
    public ICommand Save { get; set; } 
} 

그리고 XAML 코드에서

:

     <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> 
         <Button Content="Open" Style="{StaticResource EditorButtonStyle}" Command="{Open, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/> 
         <Button Content="Save" Style="{StaticResource EditorButtonStyle}" Command="{Save, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/> 
         <TabPanel IsItemsHost="True"/> 
        </StackPanel> 

이 수는 도움이되기를 바랍니다 ...

관련 문제