Slider On/Off Switch in WPF

I haven’t seen a tutorial on this exact problem, but i guess you can start by launching Expression Blend and putting a CheckBox on it. Then select the CheckBox, go to main menu – Object -> Edit Style -> Edit a Copy This will make Blend generate the default style of CheckBox so you’re able … Read more

Custom IServiceProvider in WPF

The ProvideValue method lets you override anyways whatever logic you desire to overcome the shortcoming of overriding IServiceProvider. I have not tried out the code below, instead it is a sketch of how we could design a custom service provider, preferably as a singleton and other functionality that is usual to add in a dependency … Read more

When would ShowDialog() return null?

The method always returns true or false, and this is always equal to the DialogResult property of the window at the time it closes. But the DialogResult property is null before the window is closed, and another thread could check the property. So it kind of makes sense that the return value is a nullable … Read more

Create a control in Resources and reuse it in XAML WPF

When you define a arbitrary Control in Resources, you can use it in the future in Control which have property Content and derived from Control class. These are the followings: ContentControl, Label, ContentPresenter, etc. Also you must set x:Shared=”False” for resource if you want to use this resource in many Controls, because x:Shared=”True” by default … Read more

WPF MVVM INotifyPropertyChanged Implementation – Model or ViewModel

The thing is that if you were following MVVM, you would have a BookViewModel for your Book model class. So you would have a INotifyPropertyChanged implementation on that view model. Exactly for that purpose MVVM exists (but not only). That being said, the INotifyPropertyChanged has to be implemented on view model classes, not models. UPDATE: … Read more

WPF Datagrid Performance

Since I can’t see your source code it is quite hard to help you. Especially since the performance of a WPF application is influenced by a lot of things. For some hints on what to look out for see Optimizing WPF Application Performance. And yes – it greatly matters what xaml is used in each … Read more

What is .baml file?

A compiled XAML file. Wikipedia says: A XAML file can be compiled into a .baml (Binary XAML) file, which may be inserted as a resource into a .NET Framework assembly. At run-time, the framework engine extracts the .baml file from assembly resources, parses it, and creates a corresponding WPF visual tree or workflow.

Bind command to Loaded event of view

If you want to bind command to the Loaded event, you should use the “System.Windows.Interactivity” assembly. <UserControl x:Class=”Components.Map.MapView” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:map=”clr-namespace:Components.Map” xmlns:controls=”clr-namespace:Windows.Controls;assembly=Windows.Controls” xmlns:ValidationRules=”clr-namespace:Windows.Controls.ValidationRules;assembly=Windows.Controls” xmlns:directGraphicsControl=”clr-namespace:Windows.DirectGraphicsControl;assembly=Windows.DirectGraphicsControl” xmlns:colorBar=”clr-namespace:Components.Common.ColorBar;assembly=Components.Common” xmlns:RefinedRibbonControls=”clr-namespace:Components.Common.Controls.RefinedRibbonControls;assembly=Components.Common” xmlns:UserControls=”clr-namespace:Components.Common.UserControls;assembly=Components.Common” xmlns:map1=”clr-namespace:Models.Map;assembly=Models.Map” xmlns:utilities=”clr-namespace:Windows.Utilities;assembly=Windows.Utilities” xmlns:system=”clr-namespace:System;assembly=mscorlib” xmlns:i=”clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity”> <i:Interaction.Triggers> <i:EventTrigger EventName=”Loaded”> <i:InvokeCommandAction Command=”{Binding LoadedCommand}” /> </i:EventTrigger> </i:Interaction.Triggers> </UserControl> System.Windows.Interactivity.dll is in Microsoft Expression Blend Software Development Kit (SDK) (download link) and also … Read more