Binding ConverterParameter

The ConverterParameter property can not be bound because it is not a dependency property. Since Binding is not derived from DependencyObject none of its properties can be dependency properties. As a consequence, a Binding can never be the target object of another Binding. There is however an alternative solution. You could use a MultiBinding with … Read more

Pushing read-only GUI properties back into ViewModel

Yes, I’ve done this in the past with the ActualWidth and ActualHeight properties, both of which are read-only. I created an attached behavior that has ObservedWidth and ObservedHeight attached properties. It also has an Observe property that is used to do the initial hook-up. Usage looks like this: <UserControl … SizeObserver.Observe=”True” SizeObserver.ObservedWidth=”{Binding Width, Mode=OneWayToSource}” SizeObserver.ObservedHeight=”{Binding … Read more

INotifyPropertyChanged vs. DependencyProperty in ViewModel

Kent wrote an interesting blog about this topic: View Models: POCOs versus DependencyObjects. Short summary: DependencyObjects are not marked as serializable The DependencyObject class overrides and seals the Equals() and GetHashCode() methods A DependencyObject has thread affinity – it can only be accessed on the thread on which it was created I prefer the POCO … Read more

Is it possible to set code behind a resource dictionary in WPF for event handling?

I think what you’re asking is you want a code-behind file for a ResourceDictionary. You can totally do this! In fact, you do it the same way as for a Window: Say you have a ResourceDictionary called MyResourceDictionary. In your MyResourceDictionary.xaml file, put the x:Class attribute in the root element, like so: <ResourceDictionary xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” … Read more

WPF – Import image as resource

Create a folder (e.g. images) in your Visual Studio Project. Add the image file(s) to that folder. Set their Build Action to Resource (in the Properties window, see second image in this answer). Then write the UriSource property like you already did: UriSource=”/images/jamsnaps-dark.png” That URI is effectively a Resource File Pack URI, where the prefix … Read more

Virtualizing an ItemsControl?

There’s actually much more to it than just making the ItemsPanelTemplate use VirtualizingStackPanel. The default ControlTemplate for ItemsControl does not have a ScrollViewer, which is the key to virtualization. Adding to the the default control template for ItemsControl (using the control template for ListBox as a template) gives us the following: <ItemsControl ItemsSource=”{Binding AccountViews.Tables[0]}”> <ItemsControl.ItemTemplate> … Read more

Binding to static property

If the binding needs to be two-way, you must supply a path. There’s a trick to do two-way binding on a static property, provided the class is not static : declare a dummy instance of the class in the resources, and use it as the source of the binding. <Window.Resources> <local:VersionManager x:Key=”versionManager”/> </Window.Resources> … <TextBox … Read more

How to bind RadioButtons to an enum?

You can further simplify the accepted answer. Instead of typing out the enums as strings in xaml and doing more work in your converter than needed, you can explicitly pass in the enum value instead of a string representation, and as CrimsonX commented, errors get thrown at compile time rather than runtime: ConverterParameter={x:Static local:YourEnumType.Enum1} <StackPanel> … Read more