This is a Library designed to ease working within an MVVM framework, and is meant to consolidate boiler-plate ViewModel interactions for common WPF controls into pre-built classes. ## Example - A simplified ComboBox Experience A ComboBoxDefinition has the following properties that the ViewModel may interact with, and are easily bound within the XAML using a single binding. - ItemSource (The items within the drop-down) - SelectedItem (The currently selected item) - SelectedValue \ SelectedValuePath ( The value of the SelectedItem, as an object, typically a property of the item ) - SelectedItemChanged event - Occurs and a new item is selected - ItemSourceChanged event - Occurs when the itemsource is updated - IsEnabled - Enable/Disable a control from within the ViewModel - Visibilty / IsVisible - Toggle visibility of an item from within the ViewModel ## XAML: <ComboBox MvvmControls:ControlDefinitions.ComboBoxDefinition="{Binding MyComboBox}" />
$ dotnet add package RFBCodeWorks.Mvvm.ControlsThis is a Library designed to ease working within an MVVM framework, and is meant to consolidate boiler-plate ViewModel interactions for common WPF controls into pre-built classes.
| Usage | Namespace |
|---|---|
| Converters | xmlns:converters="https://github.com/RFBCodeWorks/MvvmControls/WPF.Converters" |
| Custom Controls | xmlns:cc="https://github.com/RFBCodeWorks/MvvmControls/WPF.Controls" |
| Attached Behaviors | xmlns:cb="https://github.com/RFBCodeWorks/MvvmControls/WPF.Behaviors" |
| Specialized ViewModels | xmlns:cs="https://github.com/RFBCodeWorks/MvvmControls/Mvvm/Specialized" |
These classes are the base classes the main objects are derived from, and follow a strucute similar to System.Windows.Controls namespace.
where E:IList<T>
IList<T>Items property is set to a new collectionwhere E:IList<T>
<T>, AbstractAsyncCommand, AbstractAsyncCommand<T>
<T>, AbstractAsyncButtonDefinition, AbstractAsyncButtonDefinition<T>
ButtonDefinition, ButtonDefinition<T>, AsyncButtonDefinition, AsyncButtonDefinition<T>
RelayCommand, RelayCommand<T>, AsyncRelayCommand, AsyncRelayCommand<T>
ListBoxDefinition, ComboBoxDefinition - Derived from Primitives.SelectorDefinition
WPF.Behaviors.MultiItemSelectionBehavior properties attached to a listbox, a Listbox also supports multi-item selection modes.CheckBoxDefinition, RadioButtonDefinition - Derived from Primitives.ToggleButton
Primitives.ToggleButton, and implements ICheckBoxIRadioButton.IsThreeState property to FALSE.TextControlDefinition - Derived from Primitives.ControlBase
A ComboBox has the following properties that the ViewModel may interact with:
This can all be set up within the ViewModel like so:
public class MyViewModel {
public MyViewModel()
{
MyComboBox = new ComboBoxDefinition<string>()
{
ItemSource = new string[] { "Index0", "Index1", "Index2", "Index3" }
};
ComboBoxDefinition.SelectedItemChanged += NewItemSelected;
}
public ComboBoxDefinition<string> MyComboBox { get; }
private void NewItemSelected(object sender, EventArgs e) { /* React to item selection */ }
}
And the corresponding xaml:
xmlns:cb="https://github.com/RFBCodeWorks/MvvmControls/WPF.Behaviors"
<ComboBox cb:ControlDefinitions.ComboBoxDefinition="{Binding ComboBoxDefinition}" />
This library utilizes C#9.0 for init setters.
<LangVersion>9.0</LangVersion>Build Targets:
net472, net480.NetCoreApp3.1.Net5.0-windows.Net6.0-windows.Net7.0-windows