0

Im a complete Noob to this so im having a really hard time wrapping my head around how this works.

Basically I have a Main Page that im using, and within the XAML i have created a menu


What I have is a Document (DummyDoc) that contains a TextBox within it that i am trying to send the find command to.

Ive tried this every which way and googled it but i just cant seem to get it to work for me and could use some help with a push in the right direction

Main form

 <Window>

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="clr-namespace:DMC_Robot_Editor"
        xmlns:local="clr-namespace:DMC_Robot_Editor.GUI" 

    <Menu>
    <MenuItem Header="_Edit">
     <MenuItem Header="_Cut"/>
    </MenuItem>
    <MenuItem/>
    <Grid>
     <local:DummyDoc x:Name="_Editor"/>
    </Grid>
    </Window>

That is the main form that i am using. then i have my second document "DummyDoc"

<ad:DocumentContent x:Name="document" x:Class="DMC_Robot_Editor.Controls.DummyDoc"
        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:local="clr-namespace:DMC_Robot_Editor.Controls" 
        xmlns:ed="schemas.microsoft.com/expression/2010/drawing"
        Title="Window1" Height="300" Width="300"
        IsVisibleChanged="Is_VisibleChanged"  PropertyChanged="document_PropertyChanged">
    <Grid>

        <Menu >
            <MenuItem Header="_File">
                <MenuItem Header="was here"/>
            </MenuItem>

        </Menu>
        <local:Editor x:Name="source" IsVisibleChanged="Is_VisibleChanged" TextChanged="TextChanged" UpdateFunctions="raiseupdated" />
        <local:Editor x:Name="data" Visibility="Hidden"  IsVisibleChanged="Is_VisibleChanged" TextChanged="TextChanged"      UpdateFunctions="raiseupdated"/>
    </Grid>
    </ad:DocumentContent>

DummyDoc is a window that has an Inherited Editor in it.

<avalonedit:TextEditor
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit" 
             x:Class="DMC_Robot_Editor.Controls.Editor" 
             x:Name="editor"
             mc:Ignorable="d" 
             d:DesignHeight="300"
    d:DesignWidth="300" 

    TextChanged="Text_Changed"
    IsVisibleChanged="raiseUpdate"
    MouseMove="Mouse_Move"
    MouseHover="Mouse_Hover"

    MouseHoverStopped="Mouse_Hover_Stopped" KeyUp="editor_KeyUp">


    </avalonedit:TextEditor> 

My Ultimate Question is how do i use WPF Binding to make the "Cut" Action from the main form initiate the cut() method of the textbox?

I wrote textbox in it because in code behind, im doing the following

  partial class DummyDoc:DocumentContent
    {
    public Editor TextBox{get;set;}
     private void Is_VisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (sender is Editor)
                this.TextBox = sender as Editor;

            if ((VisibilityChanged != null) && (TextBox != null))
                raiseupdated(TextBox, new FunctionEventArgs(this.TextBox.Text));
        }
    }
4

1 回答 1

1

ElementName通过查找使用您指定的字符串标识符的元素来查找元素。

你把x:Name="local:TextBox"你的文本框标签?

我认为您已经通过使用“local:TextBox”来解决问题。

对于初学者......这是用于引用命名空间中元素类型的语法......它的意思是“TextBox本地命名空间中的类型”......它无效(或者说不一样) ) 在您使用的上下文中......您应该只分配一个“标识符”字符串。

所以....

CommandTarget="{Binding ElementName=textboxFind}"

...

<TextBox x:Name="textboxFind"  ..... />

会更合适。


更新(鉴于问题正在澄清):

您应该在您的菜单项中指定一个“命令”,当您选择该菜单项时该命令将被提升。

然后,如果 TextEditor 具有焦点(......因此是命令目标......)......那么它应该看到 Cut 命令。

我希望 Avalon 编辑器能够处理众所周知的“应用程序命令”,即剪切、复制、粘贴等。

<MenuItem Header="_Cut" Command="ApplicationCommands.Cut">
于 2012-09-04T23:19:27.777 回答