0

テキストブロックとテキストボックスを備えた非常にシンプルなMVVMLightアプリケーションがあります。私がやろうとしているのは、MVVM Light Toolkitとデータバインディングを使用して、テキストブロック値をテキストボックス値に設定することです。プログラムを実行すると、テキストブロックのテキストが更新されません。

private string _name = "Test Name";

public string Name
{                
    get
    {
        return _name;
    }
    set
    {
        _name = value;
        RaisePropertyChanged("NameChanged");
    }
}

これがXAMLです。「テスト名」は正常に表示されますが、テキストボックスの値に変更されません。テキストブロック:

<TextBlock x:Name="NameTitle"
           Text="{Binding Name}"
           Margin="-3,-8,0,0"/>

テキストボックス:

<TextBox Text="{Binding Name, Mode="TwoWay"}" x:Name="tb"            
       HorizontalAlignment="Center"
       VerticalAlignment="Center"
       FontSize="40" >
       <i:Interaction.Triggers>
           <i:EventTrigger EventName="LostFocus">
             <commands:EventToCommand Command="{Binding Name}" 
                       CommandParameter="{Binding Text, ElementName=tb}" />
           </i:EventTrigger>
       </i:Interaction.Triggers>
</TextBox>
4

1 に答える 1

4

You should be passing "Name" to RaisePropertyChanged instead of "NameChanged". Another solution would be to bind the TextBlock directly to the Textbox using ElementName

XAML:

<TextBlock x:Name="NameTitle" Text="{Binding ElementName=tb, Path=Text}" Margin="-3,-8,0,0"/>
于 2012-05-06T17:46:10.153 に答える