wpf - How do I break a large XAML file into sub-XAML files and maintain communication between the parent and child objects? -


i'm new wpf. i'm attempting modify project visualstudiolikepanes book wpf 4 unleashed. because panes hidden default until run project, decided nice place pane i'm working on separate xaml file can see changes make pane without needing launch executable.

so, based on posts read here on stackoverflow few days ago, added new usercontrol sample project , plopped content of pane in question that. here usercontrol attributes in 'child' xaml file:

<usercontrol x:class="sample.settingspanel"          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"           mc:ignorable="d"> 

to include control parent, added xmlns:sp namespace 'parent' xaml file:

<window     title="mainwindow"     x:uid="window_1" x:class="sample.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:sp="clr-namespace:sample"     x:name="window"> 

i 'included' control via this:

<sp:settingspanel visibility="collapsed" x:name="layer1" x:fieldmodifier="private" /> 

i found in code-behind file 'parent' xaml file, of code made reference of elements contained in 'child' xaml file unrecognized. so, removed (or commented out) references names , objects contained within 'child' xaml file , ever since have been jumping through hoops wire things up.

for example, want 1 textbox in 'child' xaml file reflect in textbox in 'parent' xaml file. believe following binding work, but, of course, can't place 'child' xaml, because doesn't 'know' parent's 'test' element longer.

<textbox text="{binding elementname=test, path=text}" /> 

i'm sure i've broken 'parent' xaml file incorrectly. can't imagine everytime wants break segment of xaml out file must rework of code behind , set special communication hacks let elements continue communicate.

i did @ variety of posts (e.g. binding 2 usercontrols same datacontext, or viewmodel? , what easiest way break large xaml files in application?), didn't address particular question.

thanks,

matt

when split out elements usercontrol can still access them x:name field value provided. however, since new wpf start looking mvvm pattern before develop "bad habits". addresses concerns.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -