AvalonDock文档绑定

时间:2010-06-03 18:33:39

标签: c# wpf binding avalondock

我正在使用AvalonDock(link)来创建我的应用程序。我有一个工具栏和一个文档窗格(类似VisualStudio),每个新文档都包含一个文本框。现在我想在我的工具栏中添加一个撤销按钮,它将撤消对所选文档放置的文本框的更改。它与Visual Studio中的完全相同。

我想通过TabControl和Tabs回答here。 mycode的:

<Window x:Class="_app.MainWindow"
    xmlns:my="clr-namespace:_app"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"  
    xmlns:osc="clr-namespace:OpenSourceControls;assembly=DockPanelSplitter"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">

<Grid >
    <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="24"/>
    </Grid.RowDefinitions>

    <!--...Menu And Toolbars -->

    <ToolBarPanel Grid.Row="1" Width="Auto" HorizontalAlignment="Stretch" >
             <ToolBar>
                <Button Command="Undo">Undo</Button>
            </ToolBar>
   </ToolBarPanel>

    <ad:DockingManager x:Name="dockManager" Grid.Row="2">
        <ad:ResizingPanel Orientation="Vertical">
            <ad:ResizingPanel Orientation="Horizontal">
                <ad:DockablePane ad:ResizingPanel.ResizeWidth="150">
                    <ad:DockableContent x:Name="inputContent" Title="Workspace">

                          <!-- some dockable windows -->

                     </ad:DockableContent>
                </ad:DockablePane>

                    <!-- here are added the new Documents-->
                 <ad:DocumentPane Name="mainDocPane" ItemsSource="{Binding ..Don't know..}">
                    <ad:DocumentPane.ItemContainerStyle>
                        <Style TargetType="ad:DocumentContent">
                            <Setter Property="Content" Value="{Binding Content}"/>
                        </Style>
                    </ad:DocumentPane.ItemContainerStyle>
                </ad:DocumentPane>                  
            </ad:ResizingPanel>        
        </ad:ResizingPanel>
    </ad:DockingManager>
</Grid>

我创建了这样的新文档窗口:

    private void NewDocument_Click(object sender, RoutedEventArgs e)
    {
        string title = "Document" + (dockManager.Documents.Count+1).ToString();

        var doc = new Document() { Title = title };
        doc.Show(dockManager);
        doc.Activate();
    }

文档类看起来像这样:

 public partial class Document : AvalonDock.DocumentContent
{
    public Document()
    {
        InitializeComponent();
    }
}

XAML:

<ad:DocumentContent x:Class="_ap.Document"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:osc="clr-namespace:OpenSourceControls;assembly=DockPanelSplitter"
    xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock">

<DockPanel>
    <TextBox Name="input" AcceptsReturn="True" />
</DockPanel>

所以我想在上面的链接中应用相同的机制。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

See the ApplicaionCommands.Undo

将撤消按钮绑定到.NET FW附带的就地命令后,当TextBox具有焦点时,撤消将在您无需执行任何操作的情况下进行。