Archive

Archives pour 09/2022

Enum filter controls

For having a CheckBox selection for enum type like this

and make easy filter on collection

you can use this two components

  • EnumFilterControl
  • EnumFilterComboControl

EnumFilterControl

Is base control for showing enum in grid

EnumFilterComboControl

Is the same control but using ComboBox

Extra code

Styles

Common properties

Properties Descriptions Default
Title Title for control (show at left) Filter
ShowHiddenEnum Define if you must show item of enum with ExcludeFilterAttribute false

if you have an enum with (usage of attribues)

in this case when ShowHiddenEnum=true, you can show None and All

And if you use HideFilterColorAttribute on enum like this

Force to hide color even ShowColor=true

Properties Descriptions Default
ItemConverter For specify class can convert Items (IValueConverter) for color indicator and text translation or try to use TypeConverter null

TypeConverter if define, like this

usage like this

or use a TypeConverter like this

for TypeConverter the converting is automatic

Properties Descriptions Default
ShowColor define if rectangle color is visible and ItemsConverter is define for color (not return null) or TypeConverter exist and can convert to Brush true
ShowAll Show All CheckBox true
ShowNone Show None CheckBox true
AllText Text for All CheckBox true
NoneText Text for None CheckBox true
Selector Is the selectedItems for this component with

  • null if all selected
  • object[] empty if none selected
  • object[] contains enum element checked
null
AllowAll do not use, is used for disable all checkbox
AllowNone do not use, is used for disable none checkbox
All do not use, is used for check all checkbox
None do not use, is used for checknone checkbox
CheckWith for specify size of CheckBox if you want 80D
Type Is the type of enum you want to show null

Usage

in xaml

for filtering

Categories: Non classé Tags:

SelectedItems for ListView

SelectedItems not exist for LisView you can use this code for adding this property and using binding

and usage like this

 

Categories: Non classé Tags:

ValidationRules with binding

It’s not possible to have a binding in ValidationRule because this validation rule class is not in visual hierachical tree, and sometime is necessary to chech for example is the text is not in list of the DataContext or or two DateTime, start and end are consistent together.

See my sample for Text and List in DataContext

Window for test

and xaml

and two class for using

DataContextObject for storing DataContext of TextBox

and ValitationRule

see more sample in

https://stackoverflow.com/questions/3862385/wpf-validationrule-with-dependency-property

https://docs.microsoft.com/fr-fr/dotnet/desktop/wpf/data/how-to-implement-binding-validation?view=netframeworkdesktop-4.8

and if you want to have best design of error for ValidationRule

here somes template for validation error

and for factorize for all textbox

 

Categories: Non classé Tags: