如何将命令绑定到Windows Phone中的文本框

时间:2013-11-23 11:32:55

标签: mvvm windows-phone-8

我想将命令绑定到文本框。我试过下面的代码。但它没有用。

<TextBox x:Name="txtReview" MaxLength="1000" Text="{Binding Mode=TwoWay,Path=Comments}"   HorizontalAlignment="Left" Height="215" Margin="10,184,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="326" InputScope="Default" VerticalScrollBarVisibility="Auto">
        <i:Interaction.Triggers>
            <i:EventTrigger>
                <i:InvokeCommandAction  Command="{Binding textchangedcommand, Mode=OneWay}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </TextBox>

1 个答案:

答案 0 :(得分:2)

这可以解决您的问题:

<TextBox x:Name="txtReview" MaxLength="1000" Text="{Binding Mode=TwoWay,Path=Comments}"   HorizontalAlignment="Left" Height="215" Margin="10,184,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="326" InputScope="Default" VerticalScrollBarVisibility="Auto">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="TextChanged">
            <i:InvokeCommandAction Command="{Binding textchangedcommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TextBox>