I love WPF

"jamais sans son interface"

I love WPF

"jamais sans son interface"

Simple ScrollViewer With Offset in DP

if you want a ScollWiever with offsets use public class ScrollViewerEx : ScrollViewer, INotifyPropertyChanged { static ScrollViewerEx() { //ScrollViewer.VerticalOffsetProperty.OverrideMetadata(typeof(ScrollViewerEx), // new FrameworkPropertyMetadata(0.0, (d, e) => // { // ScrollViewerEx control = d as ScrollViewerEx; // control.ScrollToVerticalOffset((double)e.NewValue); // })); //ScrollViewer.HorizontalOffsetProperty.OverrideMetadata(typeof(ScrollViewerEx), // new FrameworkPropertyMetadata(0.0, (d, e) => // { // ScrollViewerEx control = d as ScrollViewerEx; // […]

Clipping a control from another control (with binding)

If you want to clip a control form another control you can use this markup (showed only in run) public class Geometry : MarkupExtension { private static DependencyProperty ReferenceBindingSinkProperty = DependencyProperty.RegisterAttached(« ReferenceBindingSink », typeof(object), typeof(Geometry), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); public BindingBase Reference { get; set; } public override object ProvideValue(IServiceProvider serviceProvider) { IProvideValueTarget target = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; […]

EnumExtension with contains

For simplify flag enum usage use this code public static class EnumExtension { /// <summary> /// convert enum value to int value /// </summary> /// <typeparam name= »T »>T must be an Enum</typeparam> /// <param name= »soure »>Enum of type T</param> /// <returns>int value of enum</returns> public static int ToInt<T>(this T soure) where T : IConvertible//enum { if (!typeof(T).IsEnum) […]

ToolTips with StringFormat when it’s don’t work

If you want bind a tooltip with value and have a StringFormat of a slider for exemple… the StringFormat is not apply (for tag or another property it’s the same behavior) For solve it use this code <Slider x:Name= »slider » HorizontalAlignment= »Left » Background= »LightCoral » Height= »29″ Margin= »37,162,0,0″ TickFrequency= »1″ Tag= »{Binding Value, RelativeSource={RelativeSource Self}, StringFormat=N2} » VerticalAlignment= »Top » Value= »0″ Width= »350″> <Slider.ToolTip> <ToolTip DataContext= »{Binding […]

ToolTip on moving thumb for slider

I try to find a solution for having in slider a tooltip moving under thumb when i drag it after reading somes post like :https://stackoverflow.com/questions/1178134/wpf-adding-a-tooltip-to-the-track-of-a-slider i think that restyle slider is not a good solution when you using already restyled slider as mahapp for example and microsoft good explain for tooltip position : https://docs.microsoft.com/fr-fr/dotnet/framework/wpf/controls/how-to-position-a-tooltip So i […]

Draw lines at real pixel position

If you want to draw lines in OnRender function for sample, you have a antialiasing and you can’t have a real position (at pixel) with this code (find in https://stackoverflow.com/questions/6018106/wpf-drawingcontext-seems-ignore-snaptodevicepixels) you can solve it public static class SnapDrawingExtensions { public static void DrawSnappedLinesBetweenPoints(this DrawingContext dc, Pen pen, double lineThickness, params Point[] points) { var guidelineSet = […]

Converter is a Markup

If you want simplify your code it’s better to make a converter who is also a markup Previous code for converter public class BoolToVisivilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) […]

Apply stroke to a textblock

find on https://stackoverflow.com/questions/93650/apply-stroke-to-a-textblock-in-wpf using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Documents; using System.Windows.Markup; using System.Windows.Media; namespace MyNotes { [ContentProperty(« Text »)] public class OutlinedTextBlock : FrameworkElement { public static readonly DependencyProperty FillProperty = DependencyProperty.Register( « Fill », typeof(Brush), typeof(OutlinedTextBlock), new FrameworkPropertyMetadata(Brushes.Black, FrameworkPropertyMetadataOptions.AffectsRender)); public static readonly DependencyProperty StrokeProperty = DependencyProperty.Register( « Stroke », […]

ProgressBar with percent text

If you want a progress bar with text two colors you can use this public class ProgressBarText : ProgressBar { static ProgressBarText() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressBarText), new FrameworkPropertyMetadata(typeof(ProgressBarText))); } #region IndicatorColor (DP SHORT) public Brush IndicatorColor { get { return (Brush)GetValue(IndicatorColorProperty); } set { SetValue(IndicatorColorProperty, value); } } public static readonly DependencyProperty IndicatorColorProperty = DependencyProperty.Register(« IndicatorColor », typeof(Brush), typeof(ProgressBarText), […]

Retour en haut