私は束を持っていますtextboxes
私はビューモデル内の文字列にバインドしようとしています。私はすべてが正しく設定されていると思ったが、テキストボックスには何も表示されていない。テキストボックスが正しくバインドされていません
ここに私のXAMLと、私がバインドしようとしているテキストボックスの1つがあります。
<Window x:Class="Server.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:l="clr-namespace:Server"
xmlns:viewmodel="clr-namespace:Server.ViewModels"
Title="MainWindow">
<Window.DataContext>
<viewmodel:MainWindowViewModel />
</Window.DataContext>
<TextBlock Name="ShipLatTB"
FontSize="17"
Text="{Binding Path=CurrentShipLat, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
ここでのviewmodelです:
namespace Server.ViewModels
{
class MainWindowViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _currentShipLat;
public string CurrentShipLat
{
get { return _currentShipLat; }
set { _currentShipLat = value; OnPropertyChanged("CurrentShipLat"); }
}
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
私はデータがコマンドで「テスト」と、それは同じ設定で「_currentShipLat」に実際にあることを確認するためにテストし、それを検証するデバッグ。他に何が間違っているか分からない?
注:このテキストボックスは、動的に更新できるものとしています。
編集:downvoteと投票を閉じる理由を与えるのはどうですか?それは誰にも役立たない。
WPFウィンドウの初期化後に_currentShipLatフィールドを設定しましたか?そうすれば、WPFはプロパティー変更イベントをトリガーしないため、この変更を '参照'しません。 ウィンドウが初期化される前にフィールドが設定されていることを確認するか、フィールドを直接設定する代わりにプロパティのセッターを使用してください。 –
TextBlockの位置にxamlを投稿できますか?私はあなたのソリューションを読み込んで、私のために値が正しく設定されました。 –
@NathanSwannetあなたは正しかった!私はそれが初期化された後に設定していたので、私はsetterプロパティを使用しなければなりませんでした。すべてが今働きます。これを答えにしたいなら、それをマークします。 – pfinferno