Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF:如何使用命令获取我的文本框文本属性_Wpf_Binding_Textbox - Fatal编程技术网

WPF:如何使用命令获取我的文本框文本属性

WPF:如何使用命令获取我的文本框文本属性,wpf,binding,textbox,Wpf,Binding,Textbox,这就是我所尝试的: <TextBox Name="TextBoxLatter"> <i:Interaction.Triggers> <i:EventTrigger EventName="KeyDown"> <i:InvokeCommandAction Command="{Binding Path=TextBoxKeyDownCommand}"

这就是我所尝试的:

<TextBox Name="TextBoxLatter">
    <i:Interaction.Triggers>
          <i:EventTrigger EventName="KeyDown">
               <i:InvokeCommandAction Command="{Binding Path=TextBoxKeyDownCommand}"
                                      CommandParameter="{Binding ElementName=TextBoxLatter, Path=Text}"/>
           </i:EventTrigger>
  </i:Interaction.Triggers>
</TextBox>

如果您处理的是
KeyUp
事件,而不是
KeyDown
,则当前方法应该有效

但是您应该将
textboxlater
Text
属性绑定到视图模型的
string
源属性。然后,您可以在命令的
Execute
方法中直接访问它:

public void Execute(object _)
{
    string text = this.YourProperty;
    //...
}
XAML:

<TextBox Name="TextBoxLatter" Text="{Binding YourProperty, UpdateSourceTrigger=PropertyChanged}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="KeyDown">
            <i:InvokeCommandAction Command="{Binding Path=TextBoxKeyDownCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TextBox>

<TextBox Name="TextBoxLatter" Text="{Binding YourProperty, UpdateSourceTrigger=PropertyChanged}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="KeyDown">
            <i:InvokeCommandAction Command="{Binding Path=TextBoxKeyDownCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TextBox>