silverlight - How do I fix this Simple Styling Usercontrol with dependencyproperties on Title and Content? -


I have a Silverlight XML user control that I want to use to show that elements are grouped together into layouts is done. Xaml is:

  & lt; UserControl x: class = "StylingLibrary.FieldSet" 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 "xmlns: system =" clr- Namespace: system; assembly = mscorlib "mc: Ignorable =" d "d: DesignWidth =" 200 "D: DesignHeight =" 200 "& gt; & Lt; Grid X: Name = "FieldTotalout Route" Horizontal Alignment = "Statch" Vertical Element = "Stretch" & gt; & Lt; Frontline horizontal alignment = "statch" vertical alignment = "statch" style = "{static resource fieldset board}" & gt; & Lt; ContentPresenter x: name = "TheFieldsetContentPresenter" content = "{binding content}" horizontal align = "statch" vertical alignment = "statch" margin = "0" /> & Lt; / Border & gt; & Lt; Frontline horizontal tracing = "left" vertical alignment = "top" style = "{static resource field settings tagrequiry}" & gt; & Lt; TextBlock x: Name = "FieldsetTitleTextBlock" horizontal alignment = "left" vertical alignment = "top" text = "{binding title}" style = "{static resource fieldsettitle}" /> & Lt; / Border & gt; & Lt; / Grid & gt; & Lt; / UserControl & gt;   

and its support codes have largely dependency properties:

  public partial class FieldSet: UserControl {Public FieldSet () {TheFieldsetContentPresenter.DataContext = this; FieldsetTitleTextBlock.DataContext = This; // InitializeComponent () required to initialize recursive; } Public string title {get {return (string) getValue (TitleProperty); } Set {set value (title, property, value); }} Only the dependency property title for the public static reading .repo = Dependency Property. Controls ("TitleProperty", typef (string), typef (field set), blank); Public New Framework Element Content {Receive (Framework Element) Gatevalue (MyntantProperty);} Set {Set Value (MistentProperty, Value);}} Dependency Dependence for public static reading MyContentProperty = DependencyProperty.Register ("ContentProperty", Typef (Framework Element), Typef (Fieldset), Blank;);}   

Now when I try to use it:

  & lt ; Styling: Fieldsets Title = "Q "Studies: Fieldset">   

Visual Studio (2010) tells me that a NullReferenceException Was thrown and it can not make an example of FieldSet, while trying to create and run a project, this error is:

  {System.Windows.Markup.XamlParseException: This type of creator Traffic of 'StylingLibrary.FieldSet' which matches the specified binding, barriers threw an exception [line: 81 Position: 44] ] ---> System.NullReferenceException: The object reference is not set to an instance of an object. On StylingLibrary.FieldSet..ctor () --- Internal Exceptions Stack End of Trace --- On System. Windows.Application. Projects Overview on Load Components (Object Component, Uri Resolococator). View. Projects list..technics (ProjectslistWomenM)}   

What have I done wrong here?

constructor

  Change Public Area () {InitializeComponent (); TheFieldsetContentPresenter.DataContext = This; FieldsetTitleTextBlock.DataContext = This; }   

First you want to initialize the components, then you can set them to DataContext .

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -