Archive

Archives pour la catégorie ‘wpf’

Border with real ClipToBound

When we use Border, the corner radius is not used for ClipToBound
see the solution with another border

 

Categories: wpf Tags: ,

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)

Create VisualBrush in Window.Resource

And using

If you want to specify using of this VisualBrush

Stretch= »None » Define how the render is made
TileMode= »Tile » Define how the render of each object is made
AlignmentX= »Left » First aligment on X on render
AlignmentY= »Top » First aligment on Y on render
ViewportUnits= »Absolute » Type of viewport unit, if absolute no dependency of control, otherwise else
Viewport= »0,0,12,12″ According of ViewportUnit definition

Sample

Result

canvas-view

Categories: Non classé, wpf Tags:

Override custom color

for overriding custom color like

redefine the same SolidColorBrush with the same Key

 

Categories: wpf Tags:

FrameworkElement to BitmapSource Extension methode

An extension methode for transforme all FrameworkElement to BitmapSource

 

Categories: wpf Tags:

All Binding expression

Show all binding possibility i have seen

Simple binding Description
{Binding}
{Binding .}
 Binding to DataContext
{Binding Name}
{Binding Path=Name}
 Binding to « Name » property of object contained in DataContext
{Binding Selected.Name}
{Binding Path=Selected.Name}
 Binding to Selected and inside selected to « Name » property of object contained in DataContext
Binding to xaml object Description
{Binding Width,ElementName=alpha}
{Binding Path=Width,ElementName=alpha}
Binding to another control in xaml (x:Name must be specified)
{Binding DataContext.IsDirty,ElementName=alpha} Binding to DataContext contained in Control named alpha and set IsDirty
Binding to static Description
{Binding Source={x:Static s:DateTime.Now}}
{x:Static s:DateTime.Now}
 Binding on Static DateTime with
{Binding Source={StaticResource ElementKey}}
{StaticResource ElementKey}
 Binding on StaticResource named « ElementKey »
{Binding Source={DynamicResource ElementKey}}
{DynamicResource ElementKey}
 Binding on DynamicResource named « ElementKey »
{x:Static diisyetem:Node.Nodes}  Binding on static Nodes
Binding to Singleton Description
{Binding ShowGrid, Source={x:Static local:DesignBackgroundDatas.Current }}  Binding on current static local:DesignBackgroundDatas (singleton current) and binding to ShwoGrid
binding self to compoment Description
Width=“{Binding ActualHeight, RelativeSource={RelativeSource Self}}“ Binding to itself for setting Width from ActualHeight
binding to template (for CustomControl) Description
{TemplateBinding ToolPlay} Simple binding to property of CustomControl
{Binding PlayCommand, RelativeSource={RelativeSource TemplatedParent}} Same as previous but can speciy if necessary Mode, Converter etc …
or when templatebinding don’t work (sometime possible)
binding parent élément (hierarchical find) Description
{Binding Foreground,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}} Binding on Foreground of parent Button (first find)
{Binding Path=Tag,RelativeSource={RelativeSource Mode=FindAncestor,AncestorLevel=2,AncestorType=Grid} Binding on tag of second parent grid (on up from compoment first grid parent finded is ignored and second is set)
Binding to attached property Description
{Binding Path=(local:Attached.Test),
RelativeSource={RelativeSource Self}}
Specified with () Binding to AttachedTest property of current control (self)
attached property are set only for Control (you must specify it)
{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContentControl},
Path=(AutomationProperties.AutomationId)} »
Same as previous but with ancestor for binding to attached property AutomationProperties.AutomationId of contentcontrol
Samples
<TextBlock x:Name=“t1“ local:TestClass.Test=“abc“ Grid.Column=“3“/>
<TextBlock Text=“{Binding Path=(local:TestClass.Test), ElementName=t1}“/>
<TextBlock Text=“{Binding (Grid.Column), ElementName=t1}“/>
Binding to array/Collection (specific) Description
{Binding Food[2]} Binding of element 2 of array Food
Content=“{Binding Path=/}“ / char set the binding of current item in collection (in datacontext)
Content=“{Binding Path=/IsDirty}“ Same as previous with set of IsDirty property of current item in collection
MultiBinding Description
<MultiBinding StringFormat=“{}{0} x {1}“>
<Binding Path=“Width“ />
<Binding Path=“Height“ />
</MultiBinding>
Binding for create a text without converter
<MultiBinding Converter=“{StaticResource MultiValueConverter}“>
<Binding Path=“FirstName“/>
<Binding Path=“Surname“ />
</MultiBinding>
with
<local:NameMultiValueConverter x:Key=“NameMultiValueConverter“ />
Multibinding using IMultiValueConverter
public class NameMultiValueConverter : IMultiValueConverter
{
public object Convert(object[] values,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture) {
return String.Format(“{0} {1}“, values[0], values[1]);
}
}
Categories: wpf Tags: ,

Synchronize Listbox SelectedItem with component

For synchronize SelectedItem with focused component in DataTemplate for exemple

 

Categories: wpf Tags: , , ,

DoEvents WPF

here is the common code for having DoEvents() function for WPF

place this in App class and use App.DoEvents();

Categories: wpf Tags: