2013-03-21 36 views
1

好的,我修改了選項卡控件模板,添加了兩個按鈕,一個打開,另一個與其他選項卡一起保存。WPF OnMouse Up from Template

我需要做的是讓按鈕在窗口內部運行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 2013-03-21 17:45:58

+0

那麼我怎樣才能使控制模板運行在它使用的窗口中的函數呢? – 2013-03-21 17:47:37

+0

綁定到'ICommand'不行嗎? – 2013-03-21 20:24:08

回答

0

您可以使用命令和綁定來執行此操作。您可以在主窗口中設置保存和關閉命令,然後使用RelativeSource來製作bindng。你可以有這樣的窗口:

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代碼:

​​

希望這可以幫助...