vb.net - WPF binding with .NET object not communicating the data -
i following tutorial on wpf data binding. trying bind .net object's property xaml control control not display expected data. these believe relevant sections of code:
in procedural code: (note: removed observablecollection in photogallery after original post)
namespace photogallery partial public class mainwindow inherits window private photos new photos ... end class namespace photogallery public class photos inherits collection(of photo) ... end class
in xaml (solution/project name ch13-photogallery):
<window x:class="photogallery.mainwindow" ... xmlns:local="clr-namespace:ch13_photogallery.photogallery" ...> <window.resources> <local:photos x:key="photos"/> </window.resources>
and control not displaying data, size of photos collection:
<label x:name="numitemslabel" background="aliceblue" fontsize="8" content="{binding source={staticresource photos}, path=count}"/>
when typed in < label >, intellisense popped 'count' path property, think tells me have defined correctly.
if add line of procedural code behind refresh() method:
numitemslabel.content = photos.count
then count displayed correctly.
but i'm not getting binding in xaml display photos.count.
this creates new instance of photos
class:
<local:photos x:key="photos"/>
if want bind photos
collection have created in mainwindow.xaml.vb
file should expose public property - can bind properties not fields - , set datacontext
of window instance of class property defined, i.e. window class in case:
class mainwindow public property photos photos public sub new() ' call required designer. initializecomponent() datacontext = me ... end sub end class
you can bind directly property:
<label x:name="numitemslabel" background="aliceblue" fontsize="8" content="{binding path=photos.count}"/>
Comments
Post a Comment