I love WPF

"jamais sans son interface"

I love WPF

"jamais sans son interface"

Non classé

VisualBrushExtension for convert canvas to visual brush (and allow binding)

if you want to use a canvas for visualbrush like this <Canvas x:Key= »elevator »> <Path Data= »M26.348037,45.917002 L34.833,55.813073 34.833,61.750937 29.176387,55.021551 29.176387,64.125999 23.519687,64.125999 23.519777,55.021551 17.863077,61.750937 17.863077,55.813073 z M5.656612,45.916999 L11.31331,45.916999 11.313221,55.021447 16.969923,48.292065 16.969923,54.229925 8.4849611,64.125996 0,54.229925 0,48.292065 5.656612,55.021447 z M31.666273,28.499435 L31.666273,31.666169 33.249588,31.666169 33.249588,28.499435 z M13.722118,27.971731 L20.75918,27.971731 C24.277809,27.97163 26.037124,34.129095 26.037124,34.129095 L26.916732,38.52734 24.277809,39.40695 C23.984607,35.888413 23.398202,35.008704 23.398202,35.008704 23.398202,35.008704 22.225292,32.663079 21.638887,32.369877 L21.959789,39.582852 12.523508,39.582852 12.842511,32.369877 […]

DoubleAnimation with Step

For having step working in double animation use public class DoubleAnimationStep : DoubleAnimationUsingKeyFrames { #region static static DoubleAnimationStep() { DurationProperty.OverrideMetadata(typeof(DoubleAnimationStep), new FrameworkPropertyMetadata(new Duration(), (ss,ee) => (ss as DoubleAnimationStep).Update())); } #endregion #region Step (DP SHORT) public int Step { get { return (int)GetValue(StepProperty); } set { SetValue(StepProperty, value); } } public static readonly DependencyProperty StepProperty = […]

Adding font in wpf application

For using a font in resource Add font ton project and set it as resource (for sample https://www.1001fonts.com/saligra-font.html) Use it in xaml as FontFamily= »./#Saligra » without extension sample <TextBlock Text= »SAMPLE » DockPanel.Dock= »Top » FontFamily= »./#Saligra » /> see : https://wpf.2000things.com/tag/embedding-fonts/

TextBlock with ellipsis at left or center

If you want a TextBlock with ellipsis a Left, Center or Right use thisyou must use TrimmedText in place of Text for binding original text [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] public enum EllipsisPosition { // // Résumé : // Par défaut. elispsis sur la droite. Right = 0, // // Résumé : // elispsis sur la […]

AddRange for ObservableCollection

An extension methode for addinf AddRange to ObservableCollection<T> public static class ObservableCollectionExtension { public static void AddRange<T>(this ObservableCollection<T> collection, IEnumerable<T> list) { foreach (var item in list) { collection.Add(item); } } }  

UniformGrid with two orientations

for many applications we need to have an  uniform grid with Orientation (horizontal or vertical) VericalOriention (top or bottom) for positionning first element and finaly can use  FlowDirection (LegftToRight or Right to left) with this code #define INFOS using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; namespace […]

Control for menu Item collection

A simple CustomControl for using collection in MenuItem with another MenuItem from article : https://www.codeproject.com/Articles/22834/MenuItems-Collections-within-a-MenuItem opriginal source code : MenuItems_Src CustomControl public class MenuItemCollection : MenuItem { static MenuItemCollection() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MenuItemCollection), new FrameworkPropertyMetadata(typeof(MenuItemCollection))); } #region Constructor & OnApplyTemplate public MenuItemCollection() { } public override void OnApplyTemplate() { base.OnApplyTemplate(); } #endregion #region Dependency Property //public static readonly DependencyProperty […]

Binding for non hierarchical object

If you have an object who is not in herarchical tree, like converter, you cannot bind something even you have define DependyProperty on it. first you must prepare you converter for having DependencyProperty by override DependencyObject public class SelectionConverter : DependencyObject, IMultiValueConverter then create DependencyProperties #region Window (DP SHORT) public object Window { get { […]

Share an created object in resource

If you want to share a same object created, even this is create in hierachical tree you can by using x:Shared= »true » like this <local:SelectionConverter x:Key= »sc » x:Shared= »false » Color= »Blue »/> it’s a good solution for shared parameters on objects

WPF Application single instance

for WPF if you want to have a single instance (for one session) you can use this code public class ApplicationSingleInstance : Application { protected override void OnStartup(StartupEventArgs e) { var currentSessionID = Process.GetCurrentProcess().SessionId; var currentProcessId = Process.GetCurrentProcess().Id; var exists = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)); var result = exists.Where(p => p.SessionId == currentSessionID && p.Id != currentProcessId) .OrderBy(p […]

Retour en haut