RFBCodeWorks.Mvvm.Controls
1.0.0.5
See the version list below for details.
dotnet add package RFBCodeWorks.Mvvm.Controls --version 1.0.0.5
NuGet\Install-Package RFBCodeWorks.Mvvm.Controls -Version 1.0.0.5
<PackageReference Include="RFBCodeWorks.Mvvm.Controls" Version="1.0.0.5" />
paket add RFBCodeWorks.Mvvm.Controls --version 1.0.0.5
#r "nuget: RFBCodeWorks.Mvvm.Controls, 1.0.0.5"
// Install RFBCodeWorks.Mvvm.Controls as a Cake Addin #addin nuget:?package=RFBCodeWorks.Mvvm.Controls&version=1.0.0.5 // Install RFBCodeWorks.Mvvm.Controls as a Cake Tool #tool nuget:?package=RFBCodeWorks.Mvvm.Controls&version=1.0.0.5
MvvmControls
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.
Mvvm.Primitive Classes
These classes are the base classes the main objects are derived from, and follow a strucute similar to System.Windows.Controls namespace.
- ControlBase : ObservableObject
- Properties:- bool IsEnabled { get; set; }
- bool IsVisible { get; set; }
- Visibility Visibility { get; set; }
- Events:
- VisibilityChanged
- Properties:- bool IsEnabled { get; set; }
- ItemSource<T,E> : ControlBase
where E:IList<T>
- Base class for an ItemSource control.
- Type Parameters
- T : The object that will be housed in the collection of type E
- E : The collection type - Must implement
IList<T>
- Properties
- string DisplayMemberPath - Set which property to display (for example, display the 'Name' in the combobox)
- E Items - The collection of items
- Events:
- ItemSourceChanged - occurs when the
Items
property is set to a new collection
- ItemSourceChanged - occurs when the
- SelectorDefinition<T,E,V> : ItemSource <T,E>
where E:IList<T>
- Extends the ItemSource<T,E> class for use with Selector controls, such as ComboBox and ListBox
- Properties:
- T SelectedItem -- The currently selected item
- string SelectedValuePath -- Optional setting that allows setting a 'ValuePath' for the control to utilize. Ex: "ID" --> SelectedValue = SelectedItem.ID
- V SelectedValue -- The currently selected value by the SelectedValuePath - This should be only set by the control, not in code.
- Events:
- SelectedItemChanged - Occurs when a new item is selected
- SelectedValueChanged - Occurs when the SelectedValue property changes
- AbstractCommand, AbstractCommand
<T>
, AbstractAsyncCommand, AbstractAsyncCommand<T>
- These are abstract ICommand objects that implement the Community Toolkit's IRelayCommand interface
- AbstractButtonDefinition, AbstractButtonDefinition
<T>
, AbstractAsyncButtonDefinition, AbstractAsyncButtonDefinition<T>
- These are abstract classes that implement the IButtonDefinition & ICommand interfaces, for use with to bind with to the button control
- ToggleButtonDefinition
- Base class for RadioButton and CheckBox button definitions
Concrete Classes
ButtonDefinition, ButtonDefinition
<T>
, AsyncButtonDefinition, AsyncButtonDefinition<T>
- These sealed classes are derived from their respective abstract versions.
- They utilize IRelayCommand objects to implement ICommand.
RelayCommand, RelayCommand
<T>
, AsyncRelayCommand, AsyncRelayCommand<T>
- These ICommand objects are sealed, but are derived from their respective abstract primitives.
ListBoxDefinition, ComboBoxDefinition - Derived from
Primitives.SelectorDefinition
- ListBox- and ComboBox- Definition objects are used to represent a user's interaction with a Listbox or ComboBox
- Both extend Primitives.SelectorDefinition with properties specific to their associated controls.
- With the
WPF.Behaviors.MultiItemSelectionBehavior
properties attached to a listbox, a Listbox also supports multi-item selection modes.
CheckBoxDefinition, RadioButtonDefinition - Derived from
Primitives.ToggleButton
- CheckBoxDefinition is directly derived from
Primitives.ToggleButton
, and implementsICheckBox
- RadioButton adds the 'GroupName' property, and implements
IRadioButton
. - RadioButton also overrides the
IsThreeState
property toFALSE
.
- CheckBoxDefinition is directly derived from
TextControlDefinition - Derived from
Primitives.ControlBase
- While a textbox would normally just be bound to a string, since this is derived from ControlBase, it allows for the enabling/disabling/visibility control over the textbox.
Additional members include:
- Func<string> GetText - A function that can be executed to set the Text property
- string Text - The text to display in the textbox
- bool IsReadOnly - Set the textbox to ReadOnly mode
- Refresh() - Invokes GetText() to update the Text property
- Refresh(object, eventargs) - Provides a way to automatically refresh the Text property by subscribing the object to an external event
- While a textbox would normally just be bound to a string, since this is derived from ControlBase, it allows for the enabling/disabling/visibility control over the textbox.
Additional members include:
A simplified ComboBox Experience
A ComboBox has the following properties that the ViewModel may interact with:
- 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
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:Behaviors="clr-namespace:RFBCodeWorks.WPF.Behaviors;assembly=RFBCodeWorks.Mvvm.Controls"
<ComboBox Behaviors:ControlDefinitions.ComboBoxDefinition="{Binding ComboBoxDefinition}" />
Development Targets
This library utilizes C#9.0 for init setters.
- If a consumer is not using C#9, you can refer to the following guide: https://blog.ndepend.com/using-c9-record-and-init-property-in-your-net-framework-4-x-net-standard-and-net-core-projects/
- The file 'CSharp9_MissingComponents.cs' is already included within this library, so the file can just be included in your project to provide the necesary components, then include the following in your project file:
<LangVersion>9.0</LangVersion>
Build Targets:
- .NetFramework
net472
,net480
.NetCoreApp3.1
.Net5.0-windows
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net5.0-windows7.0 is compatible. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
.NET Framework | net472 is compatible. net48 is compatible. net481 was computed. |
-
.NETCoreApp 3.1
- CommunityToolkit.Mvvm (>= 7.1.2)
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.39)
- RFBCodeWorks.Mvvm.IViewModel (>= 1.0.0.1)
- System.Drawing.Common (>= 6.0.0)
-
.NETFramework 4.7.2
- CommunityToolkit.Mvvm (>= 7.1.2)
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.39)
- RFBCodeWorks.Mvvm.IViewModel (>= 1.0.0.1)
- System.Drawing.Common (>= 6.0.0)
-
.NETFramework 4.8
- CommunityToolkit.Mvvm (>= 7.1.2)
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.39)
- RFBCodeWorks.Mvvm.IViewModel (>= 1.0.0.1)
- System.Drawing.Common (>= 6.0.0)
-
net5.0-windows7.0
- CommunityToolkit.Mvvm (>= 7.1.2)
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.39)
- RFBCodeWorks.Mvvm.IViewModel (>= 1.0.0.1)
- System.Drawing.Common (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- ControlDefinition bindings no longer take priority if a value was set in xaml, such as for a tooltip or content.
- Fixed NumericUpDowns focus issue when using the keyboard tab function
- Reworked the Async Commands for improved thread safety.
- Default lazy initialization of the Refreshable* itemsources
- Refreshable textbox