FROM# public TablePage() ...">

Ag_e_parser_bad_property_value Silverlight Binding Page Title

XAML:

<navigation:Page ... Title="{Binding Name}"> 

FROM#

 public TablePage() { this.DataContext = new Table() { Name = "Finding Table" }; InitializeComponent(); } 

Getting the ag_e_parser_bad_property_value error in the InitializeComponent at the point where the name is bound. I tried to add static text that works fine. If I use binding somewhere else, for example:

 <TextBlock Text="{Binding Name}"/> 

This does not work either.

I assume it complains because the DataContext is not set, but if I put a breakpoint in front of the InitializeComponent, I can confirm that it is filled and the Name property is set.

Any ideas?

+6
silverlight
source share
2 answers

You can only use data binding for properties supported by DependencyProperty . If you look at the documents for TextBlock , for example, you will find that the Text property has a corresponding TextProperty static field of type DependencyProperty .

If you look at the documents for Page , you will find that TitleProperty not defined, so the Title property is not a dependency property.

Edit

You cannot override this, but you can create an attached property: -

 public static class Helper { #region public attached string Title public static string GetTitle(Page element) { if (element == null) { throw new ArgumentNullException("element"); } return element.GetValue(TitleProperty) as string; } public static void SetTitle(Page element, string value) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(TitleProperty, value); } public static readonly DependencyProperty TitleProperty = DependencyProperty.RegisterAttached( "Title", typeof(string), typeof(Helper), new PropertyMetadata(null, OnTitlePropertyChanged)); private static void OnTitlePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Page source = d as Page; source.Title = e.NewValue as string; } #endregion public attached string Title } 

Your xaml page may now look something like this: -

 <navigation:Page ... xmlns:local="clr-namespace:SilverlightApplication1" local:Helper.Title="{Binding Name}"> 
+8
source share

Add the following to MyPage.xaml.cs:

 public new string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(Page), new PropertyMetadata("")); 

As soon as you add this property (dependency property) to your code, your code will work as usual.

0
source share

All Articles