I'd like some help with my test project. I'd like when I press one of my buttons and the letter consists in the hidden word at the textbox(hangman) to update the textbox with the revealed letter/s. Currently my logic with the guessing works but the textbox won't update.
MainWindow.xaml:
<Window x:Class="test.MainWindow"
xmlns:vm="clr-namespace:test.ViewModel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<vm:MainWindowViewModel />
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="59*"/>
<RowDefinition Height="55*"/>
<RowDefinition Height="68*"/>
<RowDefinition Height="65*"/>
<RowDefinition Height="72*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="13*"/>
<ColumnDefinition Width="34*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Grid.Row="0" Command="{Binding ButtonClick}" CommandParameter="a">
a
</Button>
<Button Grid.Column="0" Grid.Row="1" Command="{Binding ButtonClick}" CommandParameter="b">
b
</Button>
<Button Grid.Column="0" Grid.Row="2" Command="{Binding ButtonClick}" CommandParameter="c">
c
</Button>
<Button Grid.Column="0" Grid.Row="3" Command="{Binding ButtonClick}" CommandParameter="d">
d
</Button>
<Button Grid.Column="0" Grid.Row="4" Command="{Binding ButtonClick}" CommandParameter="e">
e
</Button>
<TextBox Text="{Binding Path=DisplayWordInTextbox, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2"/>
</Grid>
MainWindowViewModel.cs:
class MainWindowViewModel : INotifyPropertyChanged
{
private string displayWordInTextbox;
public string DisplayWordInTextbox
{
get
{
return displayWordInTextbox;
}
set
{
displayWordInTextbox = value;
NotifyPropertyChanged("DisplayWordInTextbox");
}
}
public MainWindowViewModel()
{
buttonClick = new RelayCommand(buttonFunction);
loadWordsFromFile();
selectWord();
displayWord();
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
}