On my MainWindow i have a textbox and it's text is binded to a MainClass which has a public string called "TBText" (has the propertychanged/raisepropertychanged on it). I also have a button that triggers an event on another 2 classes.
I have 2 other classes that both have another string set to say "ee" and when that button is pressed it fires the property changed.
In the MainClass, when a propertychanged event occours (INotifyPropertyChanged) on either of the classes, it updates that main string called "TBText".
When i click the button, the string from 1 class is set to the main string but not from the other class, meaning you only see the string from the first class and not the second (even though there is a propertychanged event going on in both classes)
I've tried using a task to sort of disconnect the UI from the actual code/business behind, but that doesn't work either.
I've atried setting the main string as a set string in the mainclass ("eeeeee") when either propertychanged events are fired, And it still only updates to the first class, not the second.
I've also tried setting the main string as the second class' string when the first class' propertychanged event fires... still only sets it as the first class' string, almost as if the second class' string is null or empty, when it isn't.
XAML (MainWindow):
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<TextBox Text="{Binding Stat, UpdateSourceTrigger=PropertyChanged}"/>
MainViewModel:
private string StatText;
public string Stat { get { return StatText; } set { StatText = value; RaisePropertyChanged("Stat"); } }
private void ClassOne_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Stat") Stat += ClassOne.Stat;
}
private void ClassTwo_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "StatsTwo") Stat += ClassTwo.StatsTwo;
}
I haven't included it in this, but when a button is pressed in the MainWindow, it's command is linked to the 2 classes and fires the same event (i've tested and they both fire at the same time). Only problem is that the first class only changes the text, second class doesnt.
And i also want to say i haven't use MVVM all that much, but im sort of comfortable with binding text/content, commands, etc.
Is there a way to fix this? because i have no idea why it doesnt work...
Edit: the class one's variable is changed by the MainWindow and the class two variable is changed by another window