I'm trying to create a bind between a TextBlock and a property at the ViewModel class which implements IPropertyChanged interface. Actually, my property changes, event invokes, but TextBlock`s value does not change.
Here is my XAML code
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Width="120"
Text="{Binding SelectedMatch.Entries[0].CompetingTeam.TeamName, Mode=TwoWay, Converter={StaticResource TeamNameConverter}}"/>
<TextBox Grid.Column="1"
Text="{Binding SelectedMatch.Entries[0].Score}"
Width="50"
FontFamily="Montserrat"/>
</Grid>
View model
public class TournamentViewerViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private MatchModel _selectedMatch;
public MatchModel SelectedMatch
{
get => _selectedMatch;
set
{
_selectedMatch = value;
PropertyChanged?.Invoke(SelectedMatch, new PropertyChangedEventArgs(nameof(SelectedMatch)));
}
}
Match model
public class MatchModel
{
public int Id { get; set; }
public List<MatchEntryModel> Entries { get; set; } = new List<MatchEntryModel>();
public TeamModel Winner { get; set; }
public int RoundNumber { get; set; }
}
MatchEntryModel
public class MatchEntryModel
{
public int Id { get; set; }
public TeamModel CompetingTeam { get; set; }
public double Score { get; set; }
public MatchModel ParentMatch { get; set; }
}
SelectedMatch change
private void MatchesListBox_SelectionChanged(object sender,
SelectionChangedEventArgs e)
{
_viewModel.SelectedMatch = (MatchesListBox.SelectedItem as MatchModel);
}
question from:
https://stackoverflow.com/questions/65845992/why-binded-textblocks-value-can-be-not-changed-after-the-property-to-which-it-i 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…