.net - Simple Property Binding Not Working in XAML -
.net - Simple Property Binding Not Working in XAML -
a simple info binding not working, not able figure went wrong although did mistakes:
usercontrol xaml:
<usercontrol x:class="purchasestockcontrol" 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" d:designheight="300" d:designwidth="300"> <grid> <textbox text="{binding path=namee}" datacontext="me"/> </grid> </usercontrol>
i want bind property namee: result "system.windows.data error: 40 : bindingexpression path error: 'namee' property not found on 'object' ''string' (hashcode=-840583197)'. bindingexpression:path=namee; dataitem='string' (hashcode=-840583197); target element 'textbox' (name=''); target property 'text' (type 'string')". not figure error , spent 2 days on it, although did bindings before :(. command code:
public class purchasestockcontrol implements componentmodel.inotifypropertychanged public event propertychanged(sender object, e componentmodel.propertychangedeventargs) implements componentmodel.inotifypropertychanged.propertychanged public sub notifypropertychanged(byval propertyname string) raiseevent propertychanged(me, new componentmodel.propertychangedeventargs(propertyname)) end sub property namee string homecoming "some value" end set(value string) notifypropertychanged("namee") end set end property public sub new() ' phone call required designer. initializecomponent() ' add together initialization after initializecomponent() call. end sub end class
main window user control:
<window x:class="mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:z="clr-namespace:wpfapp" title="mainwindow" height="600" width="800"> <grid> <z:purchasestockcontrol x:name="test"/> </grid> </window>
you did not set datacontext
of view. in constructor of view seek doing
datacontext = this;
after intializecomponents()
method call.
.net wpf xaml binding
Comments
Post a Comment