views:

19

answers:

2

if all Styles and Converters are stored in shared resource dictionary file (styles.xaml), and this file is used from various windows.

Is it possible, to pass a parameter to that file, and propagate that parameter to the converters?

I am looking for a way to pass a "origin" type parameter, so that the converters could be aware which place they are being used from? Just a hint of which window/grid is using the converter at the moment..

A: 

See this article for Converters with parameters. I assume you define the Converter resource in Resource dictionary.

http://www.switchonthecode.com/tutorials/wpf-tutorial-binding-converters

Ragunathan
yes, this article is how i found out about converter parameters. it doesn't mention any solutions to my problem though
Sonic Soul
A: 

I wonder if something like this will work:

Add a reference to the System namespace in the declaration of each Window or UserControl where you want this.

     xmlns:sys="clr-namespace:System;assembly=mscorlib"

Then in your resources section set things up like this:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
            <sys:String x:Key="WinConvertParam">IDTextForThisWindow</sys:String>
    </ResourceDictionary>
</Window.Resources>

Your binding syntax could then look something like this:

{Binding SomeProperty, 
         Converter={StaticResource thatConverterIWrote}, 
         ConverterParameter={StaticResource WinConvertParam}}

...and your Convert or ConvertBack methods in your conversion classes then become aware of the Window that's using them, provided you vary the value of that <sys:String/> from file to file.

What do you think?

Rob Perkins