2013-03-21 67 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代码:

​​

希望这可以帮助...