I love WPF

"jamais sans son interface"

I love WPF

"jamais sans son interface"

Non classé

Synchronize items Width in WrapPanel

if you want to have the same width size for each items in WrapPanel (in in ListBox for sample) you can use Grid.IsSharedSizeScope= »True » like this <Window.Resources> <DataTemplate DataType= »{x:Type local:ColorX} »> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width= »Auto » SharedSizeGroup= »ColumnSize » /> </Grid.ColumnDefinitions> <StackPanel Orientation= »Horizontal » Margin= »2″> <Rectangle Width= »40″ Height= »25″ Fill= »{Binding Brush} » Stroke= »Black » /> <TextBox Text= »{Binding Name} » IsReadOnly= »true » Background= »Transparent » VerticalAlignment= »Center » BorderThickness= »0″ Margin= »4 0 4 […]

FallbackValue for Command

When you try to connect an MVVM command, it must be better to have a fallbackvalue if binding not release a null static command return false is the solution for showed that the binding cannot be set (and not allow command) for sample if i have the command : CloseCommand in Selected in my MVVM […]

Alternative for ICollectionView (for sorting update)

When you want to sort a collection in MVVM you use ICollectionView view = CollectionViewSource.GetDefaultView(Items); view.SortDescriptions.Clear(); view.SortDescriptions.Add(new SortDescription(« DirtyName », ListSortDirection.Descending)); but if you want to update sorting in treeview for sample you can use ListCollectionView view = new ListCollectionView(collection); view.IsLiveSorting = true; SortDescription sort = new SortDescription(« DirtyName », ListSortDirection.Ascending); view.SortDescriptions.Add(sort); and set IsLiveSorting to true for sample […]

Set component in default namespace

If you want to use your own compenent you muste speicfy an xmlns:xxxx= » » in xaml and use like this <xxx:myComponent ….. if you want to set your compenent on global or specific namespace 1- create a project 2– place component in this project 3– add this line in assemblyinfo.cs of this project [assembly: XmlnsDefinition(« http://schemas.microsoft.com/winfx/2006/xaml/presentation », « UltimateCorp.Components »)] […]

ColumnDefinition visibility

To have visible Binding on ColumnDefinition (idem a RowDefinition) use this class public class ColumnDefinitionExtended : ColumnDefinition { // Variables public static DependencyProperty VisibleProperty; // Properties public Boolean Visible { get { return (Boolean)GetValue(VisibleProperty); } set { SetValue(VisibleProperty, value); } } // Constructors static ColumnDefinitionExtended() { VisibleProperty = DependencyProperty.Register(« Visible », typeof(Boolean), typeof(ColumnDefinitionExtended), new PropertyMetadata(true, new PropertyChangedCallback(OnVisibleChanged))); […]

Canvas to VisualBrush

For fill a Control you can use a canvas transformed to VisualBrush If you change part of canvas you modify directly the render of VisualBrush For this Canvas (set outside of window) <Canvas x:Name= »back » Height= »12″ Width= »12″ HorizontalAlignment= »Left » Margin= »-45,21,0,0″ VerticalAlignment= »Top » Background= »Black »> <Ellipse Height= »6″ Canvas.Left= »0″ Canvas.Top= »0″ Width= »6″> <Ellipse.Stroke> <LinearGradientBrush EndPoint= »0.5,1″ StartPoint= »0.5,0″> <GradientStop Color= »#FF4C4C4C » Offset= »0.01″ /> <GradientStop Color= »White » […]

Override System.Windows.Interactivity.EventTrigger

for capturing message for example public class EventTrigger : System.Windows.Interactivity.EventTrigger { #region CaptureEvent (DP SHORT) public bool CaptureEvent { get { return (bool)GetValue(CaptureEventProperty); } set { SetValue(CaptureEventProperty, value); } } public static readonly DependencyProperty CaptureEventProperty = DependencyProperty.Register(« CaptureEvent », typeof(bool), typeof(EventTrigger), new PropertyMetadata(false)); #endregion protected override void OnEvent(EventArgs eventArgs) { if (eventArgs is RoutedEventArgs) { (eventArgs as […]

SolidColorBrush from another SolidColorBrush

if you have initial SolidColorBrush like <SolidColorBrush x:Key= »ycolor » Color= »green » /> you can get the color or create another SolidColorBrush and using color <SolidColorBrush x:Key= »ycolor_copy » Color= »{Binding Source={StaticResource ycolor}, Path=Color} » />  

Clone visual tree with binding

here a class for clonning visualtree inside with binding public class Header : ContentControl, ICloneable { static Header() { EditorHelper.Register<BindingExpression, BindingConvertor>(); } public object Clone() { StringBuilder outstr = new StringBuilder(); //this code need for right XML fomating XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.OmitXmlDeclaration = true; XamlDesignerSerializationManager dsm = new XamlDesignerSerializationManager(XmlWriter.Create(outstr, settings)); […]

Retour en haut