DataBinding in ResourceDictionary

Posted by Vishal on Stack Overflow See other posts from Stack Overflow or by Vishal
Published on 2010-06-08T15:19:15Z Indexed on 2010/06/08 15:22 UTC
Read the original article Hit count: 525

Filed under:
|

Hi All,

I've a ResourceDictionary. In which I've defined all the commands.

<ResourceDictionary x:Class="HTCmds" 
                    x:ClassModifier="public"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:commands="clr-namespace:Commands;assembly=UIInfrastructure"
                    xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
                    xmlns:local="clr-namespace:Commands"
                    xmlns:p="clr-namespace:PresentationModels">
            <commands:CommandReference x:Key="CopyCommandReference" Command="{Binding Path=CopyCommand}"/>
    <commands:CommandReference x:Key="ExitCommandReference" Command="{Binding Path=ExitCommand}"/>
</ResourceDictionary>

I've merged this ResourceDictionary in a Windows class.

<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Commands/HTCmds.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

This window class has DataContext property set to Commands.cs class that contains all the commands and their handlers. Now, How do I bind the commands defined in ResourceDictionary with commands in DataContext of Windows class?

Thanks & Regards, Vishal.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding