c# - XAML Cannot set value of property of base class from a different assembly -
it can hard come succinct title!
i have 2 wpf projects in single solution. first, wpfapplication defines class1. second, wpfcontrollibrary defines class2 inherits class1, class3 inherits class2, , usercontrol1. shown below:
wpfapplication class1
namespace wpfapplication5 { public class class1 { public string property1 { get; set; } } }
wpfcontrollibrary class2 , class3
namespace wpfcontrollibrary1 { public class class2 { public string property2 { get; set; } } public class class3 : class2 { public string property3 { get; set; } } }
in summary, class 1 has property1, class2 has property1 (thru inheritance) , property2, , class3 has property1 , property2 (both thru inheritance) , property3. xaml user control is:
<usercontrol x:class="wpfcontrollibrary1.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:b="clr-namespace:wpfapplication5;assembly=wpfapplication5" xmlns:l="clr-namespace:wpfcontrollibrary1" mc:ignorable="d" d:designheight="300" d:designwidth="300"> <usercontrol.resources> <b:class1 x:key="test1" property1="xxx" /> <l:class2 x:key="test2" property1="xxx" property2="yyy" /> <l:class3 x:key="test3" property2="yyy" property3="zzz" /> <l:class3 x:key="test4"> <l:class3.property1>xxx</l:class3.property1> <l:class3.property2>yyy</l:class3.property2> <l:class3.property3>zzz</l:class3.property3> </l:class3> </usercontrol.resources> <grid> </grid>
the problem xaml wont compile, , gives following error:
the property 'property1' not exist in xml namespace 'clr-namespace:wpfcontrollibrary1'. property 'property1' not found in type 'class2'. attachable property 'property1' not found in type 'class3'.
it looks xaml can't cope property inherited different assembly. right, or have been looking @ long. have tried different forms of setting property1 , event tried b:property1=
, b:class1.property1=
none seem work. or have been looking @ long , over-complicated things?
i going add own answer here try , explain think happened, despite bad example quoted above, else happens by.
when instantiate object different assembly using xaml, namespace looks following:
xmlns:b="clr-namespace:wpfapplication5;assembly=wpfapplication5"
notice has assembly named. seems copy assembly bin folder. in case, crazy happened , assembly copied in hours old. consequently, though c# compile, xaml couldn't. magic happened whereby build assembly mysteriously unchecked in configuration manager. however, checking again , rebuilding still didn't rebuild exe. during excitement, visual studio crashed , restarted (is me or happen lot vs2010).
in end had remove of dll projects , build main app itself. add dll projects in , compile. worked expected.
Comments
Post a Comment