내 속성은 제대로 업데이트되지만 사용자 인터페이스는 업데이트되지 않습니다. 내가 뭘 잘못 했니?바운드 요소에 대한 UI가 업데이트되지 않습니다.
DataContext
도 XAML이 아닌 코드 숨김 생성자에서 설정했지만 그 중 하나도 작동하지 않았습니다.
뷰 모델 :
public class MainWindowViewModel : INotifyPropertyChanged
{
public MainWindowViewModel()
{
TestCommand = new RelayCommand(UpdateTest);
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged(null, new PropertyChangedEventArgs(propertyName));
}
#endregion
private string _test;
public string Test
{
get { return _test; }
set
{
_test = value;
NotifyPropertyChanged();
}
}
public ICommand TestCommand { get; set; }
public void UpdateTest()
{
Test += "test ";
}
}
보기 : 당신은 제대로 PropertyChanged
을 구현하지 않는
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Test"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{Binding Test}" />
<Button Grid.Row="1" Content="Test 2" Command="{Binding TestCommand}" />
</Grid>
</Window>
정말 고맙습니다. 내가 그것을 놓쳤다라고 생각할 수 없다 :) – Patrick