'StatusBarControl Binding MVVM Pattern in winform
I am trying to make winform in to MVVM pattern.
I am using
public ControlBindingsCollection DataBindings { get; }
in System.Windows.Forms and
public abstract class ObservableObject : INotifyPropertyChanged, INotifyPropertyChanging
in Microsoft.Toolkit.Mvvm.ComponentModel
For normal control like radion button or button it is very easy for binding view and model together.
_control.radioButton.DataBindings.Add(
"Checked",
model,
nameof(model.function_name),
true,
DataSourceUpdateMode.OnPropertyChanged);
I have some problem with Binding System.Windows.Forms.StatusBar.StatusBarPanel.Text.
I can not bind Text in StatusBarPanelCollection and StatusBarPanelCollection is in StatusBar control.
public class viewmodel : ObservableObject
{
private view _viewControl;
private Model _model;
public MainFormControlState(Model model, View view)
{
_view = view;
_model = model;
}
private void ViewModelBindings()
{
_view.radioButton.DataBindings.Add("Checked", model, nameof(model.function_name), true,
DataSourceUpdateMode.OnPropertyChanged);
veiw.statusBar.Panels[1].Text.DataBindings() // This binding does not work because Text is string;
}
}
Solution 1:[1]
Well, as the documentation very clearly tells you:
This class is not available in .NET 5 and later versions. Use the StatusStrip control instead, which replaces and extends the StatusBar control.
And indeed, if you look at StatusStrip, it does have a DataBindings property.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Blindy |
