c# - Getting access to MainWindow.xaml.cs properties from outsourced ResourceDictionary -


i working on new usercontrol lately , have make customizable, wasn't problem until figured out, have put datatemplates in external resourcedictionary in order make control more customizable.

so have? have customizable usercontrol, able call constructor so-called "templatepath" resourcedictionary loaded in usercontrol.resources. works fine!

so what's problem? datatemplates, in sepperate resourcedictionary should able bound properties of usercontrol.xaml(.cs) in order check i.e. if specific object selected.

but that's not problem. furthermore usercontrol has predefined commands, should able bound datatemplates. wasn't problem before when datatemplates still in usercontrol.xaml obviously.

the bad thing is, have outsource datatemplates, because control available users .dll , in case, there wouldn't opportunity add custom templates afterwards.

does have idea of how implement this? in advance!

€dit: be, example, resourcedictionary, dynamically loaded when usercontrol displayed:

<resourcedictionary  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:classes="clr-namespace:customcontrol" > <classes:comparenodes x:key="comparenodes"/>  <style x:key="borderhighlightstyle" targettype="border">     <setter property="cornerradius" value="6"/>     <setter property="borderbrush" value="gray"/>     <setter property="borderthickness" value="2"/>     <style.triggers>         <trigger property="ismouseover"  value="true">             <setter property="background" value="azure"/>         </trigger>         <multidatatrigger>             <multidatatrigger.conditions>                 <condition value="true">                     <condition.binding>                         <multibinding converter="{staticresource comparenodes}">                             <binding relativesource="{relativesource self}" path="datacontext"/>                             <binding source="{binding ???????????}" path="selecteditem"/>                         </multibinding>                     </condition.binding>                 </condition>             </multidatatrigger.conditions>             <multidatatrigger.setters>                 <setter property="background" value="lightgoldenrodyellow"/>                 <setter property="borderbrush" value="black"/>             </multidatatrigger.setters>         </multidatatrigger>     </style.triggers> </style> </resourcedictionary> 

as see, have no clue how bind selecteditem-property declared in usercontrol.xaml(.cs).

i found solution myself.

i created class called "bindableproperties", has properties, should bindable outside (i.e. "selecteditem") , commands. after added "bindableproperties" object resourcedictionary, loaded control.

in control, read out "bindableproperties"-object resourcedictionary , gave commands want bind to. everytime selected item changes, bindableproperties-object gets new "selecteditem", therefore stays same in control.

the thing is, object inside class , object in resourcedictionary same, allows me bind properties of "bindableproperties", has same properties usercontrol.

problem solved.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -