Archive

Archives pour la catégorie ‘Non classé’

Calendar with week number

The current calendar not allow to show week number, i have made somes update for show it like this (datepicker too)

you must create an attached property

and made corrections in style

and usage like this (with the new style you can disable show week number)

WARNING : for DatePicker is necessary to change style of CalendarItem for connect to dynamicresource of restyled style
CalendarStyle= »{DynamicResource {x:Type Calendar}} » or using redefine style of DatePicker 

UPDATE : for getting first day of a week when clicking on week number

if CalendarHelper.ClickWeekCommand is define you receive first day of week in command

like this

and using whith this command

Categories: Non classé Tags:

Connect FrameworkElement to MVVM

Somethimes it necessary in MVVM to knowing FrameworkElement for setting something

I have create an helper for getting this FrameworkElement in MVVM

and used in mvvm like this

and in xaml

and for sample to create an picture set in clipboard

 

Categories: Non classé Tags:

FocusHelper

in wpf with mvvm is not easy top set focus at element with binding
FocusHelp is made for simplify this

and adding to a focusable control

and use like this
in your datacontext object

and code for setting focus

when the set focus is set to true, the UIElement receive Focus(); and the helper re-set Binding value to False

 

Categories: Non classé Tags:

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:

Palette control

PaletteControl is control to show Numeric, Letter, Word(s), Image, Time, stringg and array of string like train panel indicators in station


it’s a package contains many control for show this and it s full customizable

you can find

Control Descriptions Animated
BasePaleteControl Base control (has no animation) No
PaletteContentControl Control for show somes content, and run animation when it change Yes
PaletteTextControl for animating text Yes
PaletteCharControl for animating char using allowedChar string Yes
PaletteNumericControl for animation char number Yes
PaletteTimeControl for showing current time Yes
PaletteStringControl for animating one string to other one string Yes
PaletteArrayControl for animation array of string Yes

 

Properties for all

Property Descriptions
AdjustTop allow to move content top
CornerRadius corner radius for control
LineColor define line color at the vertical center of control
ShowLine set if line is visible
ContentLine to replace to common line by control you want (when you use ShowLine = false)

otherwize you can set properties background, forground, borderbrush, bordertickness to set your content

Properties for animated control

Property Descriptions
AnimationTime Define time for release palette animation

Specific properties

 

BasePaletteControl & PaletteContentControl

Property Descriptions
Content content of control

 

PaletteTextControl

Property Descriptions
Text
Text for control (multi char) animation start when text change

 

PaletteCharControl

this control animate char from previous char (current) to new setted char with AllowedChar string

For sample : if you have « abcdef » in AllowedChar, this current char is a, and set d, you have an animation a->b, b->c, c->d

Property Descriptions
char
Char to set
AllowedChar
string for define allowed char, animation use it
CaseSensitive
if case sensitive if used to find char in AllowedChar
Text
Do not use

 

PaletteNumericControl

is the same work as PaletteCharControl but AllowedChar is not available and set directly a « 0123456789 »

Property Descriptions
Value int value to set
Text
Do not use

 

PaletteTimeControl

is a control to show current time, you can pause it on using IsPaused (not browsable) dependency property

 

Property Descriptions
MarginNumber
margin between two number in pixel
NumberMode
mode for show part of time, one char for each number or two number
NumericBackground
background for numeric palette
NumericBorderBrush
border brush for numeric palette
NumericBorderThickness
border thickness for numeric palette
NumericCornerRadius
corner radius for numeric palette
NumericHeight
height for numeric palette
NumericWidth
width for numeric palette
ShowSecond if you want to show second number
Separator Content for separator for hour-minute and minute-second (can’t use binding for separator because the Separator ar dupplicated)
SeparatorHour Content for separator for hour-minute
SeparatorSecond Content for separator for minute-second
IsPaused define if time running

and event SecondTick raised for each second

the common properties background, forground, borderbrush, bordertickness to set all content of this control

 

PaletteStringControl

is a control to show string, after define number of char define.

Property Descriptions
AllowedChar
same as PaletteTextControl
Casesensitive
same as PaletteTextControl
CharBackground
background for each char palette
CharBorderBrush
border brush for each char palette
CharBorderThickness
border thickness for each char palette
CharCornerRadius
corner radius for each char palette
CharCount
number of char allowed (define number of palette showed)
CharHeight
height for each char palette
CharWidth
width for each char palette
CharMargin
margin between two char

and event CompletAnim raised when animation is done

the common properties background, forground, borderbrush, bordertickness to set all content of this control

you can change color for each text palette for setting ArrayBrush (dependency property) like this

by default color is white

 

PaletteArrayControl

is ths same control as string but using an array of string to set animation to all string in array with pause between two string.

properties are same as PaletteString Control with Pause (dependency property) for setting pause between to string

the common properties background, forground, borderbrush, bordertickness to set all content of this control

you can change color for each text palette for setting ArrayBrush (dependency property) like this

by default color is white

and you can set or clear Array

Source code

All this controls are contained in UltimateCorp.Palette.dll and set in xmlns= »http://schemas.microsoft.com/winfx/2006/xaml/presentation »
also you can used directly without specify other namespace

this control are made in .net 6 made with visual studio 2022

you can find test executable PaletteExecutable

and complete project Test Palette v2

Categories: Non classé Tags:

Acces to property hidden field

If yyou want to acces easily you can show this post

https://gunnarpeipman.com/csharp-automatic-properties/#:~:text=Automatic%20property%20in%20C%23%20is,field%20or%20assign%20to%20it.&text=We%20can%20use%20attributes%20in,properties%20because%20features%20in%20different%20.

use Mono.Reflection as nuget https://github.com/jbevain/mono.reflection/

and use with

behind

see extension for sample

 

Categories: Non classé Tags:

ToolBoxIcon for wpf Control

Categories: Non classé Tags:

Popup helper for close it on click

If you want to close a Popup automatically when click on it or children, use this helper

and

see  http://ultimatespy.sytes.net/wpf/index.php/2022/03/30/togglebutton-to-control-popup/  for ToggleButtonHelper

Categories: Non classé Tags: