WPF - Why does the Visual studio design surface stop databinding when using a button ControlTemplate defined in a different assembly? -


i've been working on current project on year, , i'm trying retro fit design time data views. application has base resource dictionary contains default styles controls. application able load plugin can override or of default styles, hence why resource dictionary contained in external assembly in following example.

note: isn't such big problem supplied demo project, causing headaches in actual application highlighted problem in first place.

the view:

<usercontrol x:class="designtimedata.usercontrol1"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:local="clr-namespace:designtimedata"              mc:ignorable="d"              d:datacontext="{d:designinstance local:viewmodel, isdesigntimecreatable=true, createlist=false}"              d:designheight="300"              d:designwidth="300">     <usercontrol.resources>         <resourcedictionary>             <resourcedictionary.mergeddictionaries>                 <resourcedictionary source="/viewsmodule;component/styles.xaml" />             </resourcedictionary.mergeddictionaries>         </resourcedictionary>     </usercontrol.resources>     <grid>         <grid.rowdefinitions>             <rowdefinition />             <rowdefinition />             <rowdefinition />         </grid.rowdefinitions>          <textblock grid.row="0"                    style="{dynamicresource textstyle}"                    text="{binding row1text}" />         <textblock grid.row="1"                    style="{dynamicresource textstyle}"                    text="{binding row2text}" />         <button content="button text"                 grid.row="2"                 style="{staticresource buttonstyle}" />     </grid> </usercontrol> 

the viewmodel:

namespace designtimedata {     class viewmodel     {         private string row1text;          public string row1text         {             { return row1text; }             set { row1text = value; }         }          private string row2text;          public string row2text         {             { return row2text; }             set { row2text = value; }         }          public viewmodel()         {             row1text = "dummy row 1";             row2text = "dummy row 2";         }     } } 

the resourcedictionary(contained in external assembly):

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">      <style x:key="textstyle"            targettype="{x:type textblock}">         <setter property="background"                 value="cornflowerblue" />         <setter property="fontsize"                 value="28" />         <setter property="textalignment"                 value="center" />         <setter property="horizontalalignment"                 value="stretch" />         <setter property="verticalalignment"                 value="stretch" />         <setter property="foreground"                 value="beige" />     </style>      <controltemplate x:key="custombuttontemplate"                      targettype="{x:type button}">         <border background="{templatebinding background}"                 borderbrush="{templatebinding borderbrush}"                 borderthickness="{templatebinding borderthickness}">             <visualstatemanager.visualstategroups>                 <visualstategroup x:name="commonstates">                     <visualstate x:name="normal" />                     <visualstate x:name="mouseover">                         <storyboard>                             <objectanimationusingkeyframes storyboard.targetproperty="background">                                 <discreteobjectkeyframe keytime="0">                                     <discreteobjectkeyframe.value>                                         <lineargradientbrush startpoint="0.5,0"                                                              endpoint="0.5,1">                                             <gradientstop offset="0"                                                           color="lightblue" />                                             <gradientstop offset="1"                                                           color="darkblue" />                                         </lineargradientbrush>                                     </discreteobjectkeyframe.value>                                 </discreteobjectkeyframe>                             </objectanimationusingkeyframes>                         </storyboard>                     </visualstate>                 </visualstategroup>             </visualstatemanager.visualstategroups>             <contentpresenter  horizontalalignment="center"                                verticalalignment="center" />         </border>     </controltemplate>      <style x:key="buttonstyle"            targettype="{x:type button}">         <setter property="background">             <setter.value>                 <lineargradientbrush startpoint="0.5,0"                                      endpoint="0.5,1">                     <gradientstop offset="0"                                   color="darkblue" />                     <!--<gradientstop offset="0.5"                                   color="blue" />-->                     <gradientstop offset="1"                                   color="lightblue" />                 </lineargradientbrush>             </setter.value>         </setter>         <setter property="borderbrush"                 value="red" />         <setter property="borderthickness"                 value="3" />         <setter property="content"                 value="{binding content}" />         <setter property="padding"                 value="5,5,5,5" />         <setter property="fontsize"                 value="26" />         <setter property="width"                 value="200" />         <setter property="foreground"                 value="darkblue" />         <setter property="template"                 value="{staticresource custombuttontemplate}" />     </style> </resourcedictionary> 

if copy contents of resource dictionary directly usercontrol.resources property seems work expected, each textblock has databound text displayed , button has expected size , content. if attempt import external dictionary using resourcedictionary.mergeddictionary follows:

<usercontrol.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="/viewsmodule;component/styles.xaml" />         </resourcedictionary.mergeddictionaries>     </resourcedictionary> </usercontrol.resources> 

then designer doesn't update correctly. textblocks have no content , grid shrinks size of (hardcoded) button content.
designer appears honouring styles defined in resource dictionary presence of controltemplate appears breaking data binding. if controltemplate , associated setter in buttonstyle style block removed designer behaves normally. also, changing padding property in buttonstyle causes designer refresh data binding , appears normal, until application compiled @ point data binding breaks , minimalist design surface again.

i don't know if issue in expression blend. unfortunately don't have access blend trial version had installed has expired.

does have idea going on here , more importantly, how fix it?

a vs2012 demo solution can found here.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -