I found the link to the financial services demo that gave us the examples of loading dynamic xaml strings in this manner. Your group posted this example using Silverlight 2 (Beta 1).
Download the Silverlight2 (Beta 1) Retail Financial Services Demonstrator located half-way down on this page. If you look at the Aspect.cs class in the Controls directory under BankingDemo, you can see an example of how I am using the InitializeFromXaml.
They use this class to load embedded resources under the Aspects folder.
Tracie
They have converted that application to Beta 2, but have not released the source code.
Is release of the source code of that financial application working in Silverlight 2 Beta 2 supposed to be announced somewhere ? Or the only way to check
http://www.financialdevelopers.com from time to time ? It is interesting, if it works at
http://www.cookingwithxaml.com/meals/financials/default.html was new version just a hack which can't be released as an example of proper replacement InitializeFromXaml or it was just
forgotten.
I have a scenario where I want to load a Datatemplate dynamically.
In Silverlight 2 Beta 1 I used the InitializeFromXaml method to load the Datatemple. The reason for doing this is because the item inside the template had an event and the binding path is variable. In the runtime I am
constructing the string that represents the Datatemplate. In this string the Binding path can change.
Can someone please explain to me how Application.LoadComponent API work?
I have Page.xaml.cs class and in its constructor i'm trying to load another Xaml (say MyControl.xaml) that i have in the same project. I was using XamlReader.Load to load MyControl.xaml. Then i use the returned root element and add it as child of one
of the Canvas defined in my Page.xaml.
Well life is good so far... it displays the content. However i want to do a bit more complicated stuff - i.e add event handlers on a Button control defined in the MyControl.xaml. Yes the button has x:Name defined.
Well i got the parser error at runtime, thats when i hit upon this post.
So i go back to my constructor and change
ScrollViewer
pScroll = (ScrollViewer)XamlReader.Load(uriString);
to
Application
.LoadComponent(this,
new
Uri(fileName,
UriKind.Relative));
Grid
content = (Grid)this.Content;
Here the fileName is the uri to MyControl.xaml and "this" refers to Page.xaml?
this.Content; gives the root of the Page.xaml? How can i get hold of the root of MyControl.xaml?
I want to get hold of the root element in MyControl.xaml so that i can add it as child of a Canvas in the main page (Page.xaml).
Does Application.LoadComponent(this,
new
Uri(fileName,
UriKind.Relative)); create a tree structure of the main page without the nodes from loaded xaml?
This is real setback we definitely need this function back. In my scenario I need users to drag and drop 3rd party controls on a designer that can be loaded dynamically. So no tweaking would work [:(]
In Silverlight RC0 I want to create DataTemplate for a control generated dynamically and register some events to it. LoadComponent is bad solution because I need a lot of instances of this control and would like to cache the XAML string (not to read from
resource file each time). Therefore I think Microsoft should provide an overload for LoadComponent that will accept string as argument or return back the InitializeFromXAML method in the final release.
samcov
Participant
1673 Points
719 Posts
Re: What happened to Control.InitializeFromXaml?
Jun 22, 2008 12:01 AM | LINK
They have converted that application to Beta 2, but have not released the source code.
You can see it here - http://www.cookingwithxaml.com/meals/financials/default.html
It will be interesting to see how they got around the loss of InitializeFromXaml.
Sam...
micmit
Member
46 Points
45 Posts
Re: What happened to Control.InitializeFromXaml?
Jul 02, 2008 06:53 AM | LINK
Is release of the source code of that financial application working in Silverlight 2 Beta 2 supposed to be announced somewhere ? Or the only way to check http://www.financialdevelopers.com from time to time ? It is interesting, if it works at http://www.cookingwithxaml.com/meals/financials/default.html was new version just a hack which can't be released as an example of proper replacement InitializeFromXaml or it was just forgotten.
Raguvind
Member
6 Points
15 Posts
Re: What happened to Control.InitializeFromXaml?
Jul 08, 2008 02:46 PM | LINK
Hi,
I have a scenario where I want to load a Datatemplate dynamically.
In Silverlight 2 Beta 1 I used the InitializeFromXaml method to load the Datatemple. The reason for doing this is because the item inside the template had an event and the binding path is variable. In the runtime I am constructing the string that represents the Datatemplate. In this string the Binding path can change.
string dynamicTemplate = "<DataTemplate x:Key=\"newTemplate\">" +"<TextBox xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"" +"Text=\"test\" TextChanged=\"TextBox_TextChanged\" Text={Binding Name}/>" +"</DataTemplate>";In Silverlight 2 Beta 2 how can I do the same or can I load a datatemplate dynamicaly in the C# code.
Regards
Ragu
AngleBracket
Member
6 Points
3 Posts
Re: What happened to Control.InitializeFromXaml?
Aug 08, 2008 12:48 AM | LINK
Can someone please explain to me how Application.LoadComponent API work?
I have Page.xaml.cs class and in its constructor i'm trying to load another Xaml (say MyControl.xaml) that i have in the same project. I was using XamlReader.Load to load MyControl.xaml. Then i use the returned root element and add it as child of one of the Canvas defined in my Page.xaml.
Well life is good so far... it displays the content. However i want to do a bit more complicated stuff - i.e add event handlers on a Button control defined in the MyControl.xaml. Yes the button has x:Name defined.
Well i got the parser error at runtime, thats when i hit upon this post.
So i go back to my constructor and change
ScrollViewer
pScroll = (ScrollViewer)XamlReader.Load(uriString); toApplication
.LoadComponent(this, new Uri(fileName, UriKind.Relative));Grid
content = (Grid)this.Content;Here the fileName is the uri to MyControl.xaml and "this" refers to Page.xaml?
this.Content; gives the root of the Page.xaml? How can i get hold of the root of MyControl.xaml?
I want to get hold of the root element in MyControl.xaml so that i can add it as child of a Canvas in the main page (Page.xaml).
i got null when i didScrollbar
myScroll = (Canvas)content.FindName("myScrollBar");So can someone tell me what is going on here...
Does Application.LoadComponent(this, new Uri(fileName, UriKind.Relative)); create a tree structure of the main page without the nodes from loaded xaml?
Similarly what doesApplication.LoadComponent(url) do?
Thanks for your patience.
udithanda
Member
2 Points
1 Post
Re: Re: What happened to Control.InitializeFromXaml?
Aug 18, 2008 09:53 PM | LINK
This is real setback we definitely need this function back. In my scenario I need users to drag and drop 3rd party controls on a designer that can be loaded dynamically. So no tweaking would work [:(]
ninomk
Member
7 Points
8 Posts
Re: Re: Re: What happened to Control.InitializeFromXaml?
Oct 09, 2008 02:59 PM | LINK
In Silverlight RC0 I want to create DataTemplate for a control generated dynamically and register some events to it. LoadComponent is bad solution because I need a lot of instances of this control and would like to cache the XAML string (not to read from resource file each time). Therefore I think Microsoft should provide an overload for LoadComponent that will accept string as argument or return back the InitializeFromXAML method in the final release.
Rincewind60
Member
3 Points
3 Posts
Re: Re: Re: What happened to Control.InitializeFromXaml?
Oct 12, 2008 11:06 AM | LINK
I have only just started learning SilverLight and already I find the need to be able to create a control with dynamic xaml.
So Microsoft.
How do we create a control where the XAML is coming from the server and contains names and event handlers?
What is the solution...
(Based on the number of views for this thread I guess I'm not alone!)