XAML part:
<TextBlock x:Name="myGroup" IsEnabled="{Binding Enable}"></TextBlock> I describe the property, the class above is inherited from the INotifyPropertyChanged interface (public partial class Index: Window, INotifyPropertyChanged):
public event PropertyChangedEventHandler PropertyChanged; public bool _enable; public bool Enable { get { return _enable; } set { _enable = value; PropertyChanged(this, new PropertyChangedEventArgs(nameof(Enable))); } } I create a method to check if there is an entry in the database, based on the result of the check, the value of IsEnabled should change:
public void CheckEnable(bool result) { string connectionString = "SERVER = localhost; DATABASE = vbnzt; UID = vbnz; PASSWORD = ;"; MySqlConnection connection = new MySqlConnection(connectionString); MySqlCommand check_group = new MySqlCommand("SELECT * FROM groups WHERE liderId = " + Properties.Settings.Default.id.ToString(), connection); connection.Open(); MySqlDataReader cg_result = check_group.ExecuteReader(); if (cg_result.HasRows) { result = true; } else { result = false; } _enable = result; connection.Close(); } I call the check before loading the content (in the MainWindow_Loaded method, which is bound to this.Loaded + = MainWindow_Loaded; in the constructor):
CheckEnable(_enable); In another class (clicking the button), I call the check, passing true to it:
Index index = new Index(); index.CheckEnable(true); It is necessary that when you click on this button without restarting the application, the TextBlock value IsEnabled changes.
PropertyChangedevent. - BulsonPropertyChangedEventArgs(nameof(CreateGroup.createGroup)));it is impossible to do so, you must refer to a property belonging to the same class, and not to another. Think for yourself: the first argumentthistells which class the change occurred in, and the second argument gives the name of the property from the same class. - Bulson