wpf - Instantiate object defined in other XAML file -


i have xaml file looks this:

<!-- file1.xaml --> <m:somename xmlns:m="clr-namespace:somenamespace">     ... </m:somename> 

i have xaml file in instantiate object defined in file1.xaml , set property on object defined in file2.xaml:

<m:someothername xmlns:m="clr-namespace:somenamespace">    <m:someothername.property>        <!-- want file1.xaml object here -->    </m:someothername.property> </m:someothername> 

any ideas?

if want use xaml object, object needs extend dependencyobject. easiest way create usercontrol:

<usercontrol     x:class="somenamespace.somename"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     mc:ignorable="d"     d:designheight="300"     d:designwidth="400">      <!-- other xaml content -->  </usercontrol> 

which has own code behind file:

namespace somenamespace {     public sealed partial class somename : usercontrol     {         public somename()         {             this.initializecomponent();         }     } } 

then can instantiate control in other parts of app:

<m:someothername xmlns:m="clr-namespace:somenamespace">    <m:someothername.property>        <somenamespace:somename />    </m:someothername.property> </m:someothername> 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -