Skip to main content
Home Forums Silverlight Programming Programming with .NET - General XamlReader.Load with x:Name attribute
3 replies. Latest Post by Allen Chen – MSFT on June 12, 2008.
(0)
andrewz
Member
0 points
2 Posts
06-11-2008 12:08 PM |
I'm loading xaml via XamlReader.Load the class has a property named "Name", when loading the xaml it seems to ignore my Name attribute (I also tried x:Name). The Title property loads fine, but the Name property is always null.
public class Entity{ public string Name { get; set; } public string Title { get; set; }}
<Model:Entity xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Model="clr-namespace:SilverlightApplication1;assembly=SilverlightApplication1" x:Name="EntityNameX" Title="EntityTitleX"></Model:Entity>
<Model:Entity xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Model="clr-namespace:SilverlightApplication1;assembly=SilverlightApplication1" Name="EntityNameY" Title="EntityTitleY"></Model:Entity>
I Load the xaml using XamlReader.Load
var x = XamlReader.Load(...)
Does silverlight ignore attributes named Name?
Tim Favour
93 points
69 Posts
06-12-2008 5:20 AM |
Hi,
This is because the XamlReader.Load changed from beta 1 to beta 2 and now always creates a separate namescope so that your loaded elements cannot be found globally with root.FindName. Microsoft suuggests a workaround in the end of this tread:
http://silverlight.net/forums/t/17572.aspx
Tim
06-12-2008 10:46 AM |
I probably should have mentioned that this xaml is not for any UI controls, it is strictly for serializing data.
Allen Ch...
Star
13862 points
1,803 Posts
06-12-2008 11:14 PM |
Hi:
Please try this:
public class Entity : Control { public string Title { get; set; } } public partial class Page : UserControl { public Page() { InitializeComponent(); string s = @"<Model:Entity xmlns='http://schemas.microsoft.com/client/2007' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:Model='clr-namespace:SilverlightApplication6;assembly=SilverlightApplication6' x:Name='EntityNameX' Title='EntityTitleX'></Model:Entity>"; Control q = XamlReader.Load(s) as Control; string name= q.GetValue(NameProperty).ToString();
}
Regards