c# - Binding to a dependency property of a user control WPF/XAML -
my app looks this:
sectionheader
sectionheader
content
sectionheader
content
sectionheader user control 2 dependency properties = title , apps.
title not change apps needs bound main window view model apps property. apps property required 2 of 3 section headers.
<c:sectionheader dockpanel.dock="top" x:name="sectionresources" title="resources" apps="{binding path=apps}" /> this how @ moment. problem apps don't show up.
in sectionheader datacontext set follows allows title show up.
datacontext="{binding relativesource={relativesource self}}" apps itemssource itemscontrol in usercontrol:
<itemscontrol itemssource="{binding apps}"> so questions are:
- how can data bind usercontrol dp?
- is easier way of doing layout without usercontrols?
edit:
forgot mention apps observablecollection of appsitems.
this dp looks like:
public static readonly dependencyproperty appsproperty = dependencyproperty.register("apps", typeof (observablecollection<appsitem>), typeof (sectionheader), new propertymetadata(null, onappspropertychanged)); private static void onappspropertychanged(dependencyobject d, dependencypropertychangedeventargs e) { console.writeline("hello!!!"); var sectionheader = d sectionheader; var value = e.newvalue observablecollection<appsitem>; sectionheader.apps = value; }
give name usecontrol , try binding this
itemssource="{binding apps,elementname=root}" and root name give usercontrol
<usercontrol x:class="wpfapplication1.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" height="350" width="525" x:name="root"> it element binding user control has apps property
Comments
Post a Comment