I love WPF

"jamais sans son interface"

I love WPF

"jamais sans son interface"

Year: 2019

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 […]

Border with real ClipToBound

When we use Border, the corner radius is not used for ClipToBound see the solution with another border public class ClippingBorder : Border { protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { OnApplyClip(); base.OnRenderSizeChanged(sizeInfo); } protected void OnApplyClip() { if (this.ClipToBounds) { RectangleGeometry _clipRect = new RectangleGeometry(); _clipRect.RadiusX = _clipRect.RadiusY = Math.Max(0.0, this.CornerRadius.TopLeft – (this.BorderThickness.Left * 0.5)); […]

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