DINESH CHAUDHARI

Hi Friends,

I know that we can create a xaml controls dynamically by using CreateFromXaml method.

But

The CreateFromXaml method takes a parameter as xaml control syntax but is it possible to send parameter as a xaml file name.

or if any other way how i cretae dynamic controls by using xaml file .



Re: Silverlight (formerly WPF/E) General Discussion how i used createFromXaml method parametre as xaml file

Thiago Henrique da Silva

Hi Dinesh

I think that you can't do this directly.

Why you dont try using ajax ( atlas )

You can call a webmethod to load your xaml file and use CreateFromXaml in callback function to create you element.

cya





Re: Silverlight (formerly WPF/E) General Discussion how i used createFromXaml method parametre as xaml file

Bryant Likes

You can do this using the downloader object. There is an example in the documentation but the call looks like:

// Completed event handler for the Downloader object.
function onCompleted(sender, eventArgs)
{
    // Retrieve the id of the WPF/E control.
    var control = sender.getHost();

    // Retrieve the XAML fragment and create an object reference.
    var xamlFragment = control.createFromXamlDownloader(sender);

  // Add the XAML object as a child of the root Canvas object.
  var root = sender.findName("rootCanvas");
    root.children.add(xamlFragment);
}
This will allow you to create from Xaml file...




Re: Silverlight (formerly WPF/E) General Discussion how i used createFromXaml method parametre as xaml file

DINESH CHAUDHARI

Thanks for reply,

I tried your code but its not working,

I got error like invalid procedure or method call at line

var firstxaml=control.CreateFromXamlDownloader(first.xaml);

.

Here i will Explain my problem in detail:

I have one Main.xaml file in this file i creted a one canvas in which i want to show different xaml files and two buttons say first and second .

When i clicked on first button then my first.xaml file is loaded in canvas ,and when i clicked on second button then second.xaml is loaded in canvas.

I think you will clear with problem now.

If you any solution for this please let me know.





Re: Silverlight (formerly WPF/E) General Discussion how i used createFromXaml method parametre as xaml file

Bryant Likes

You don't pass that method a file name, you have to use the downloader object. I created a simple example of this here:

http://blogs.sqlxml.org/wpfe/downloadxaml/

Xaml: http://blogs.sqlxml.org/wpfe/downloadxaml/download.xaml

JS: http://blogs.sqlxml.org/wpfe/downloadxaml/eventhandlers.js

Take a look at that. It uses the downloader object to load the techy.xaml file which is part of the WPFEPad example (which also uses the downloader object). I didn't add the progress bar because I didn't have time.





Re: Silverlight (formerly WPF/E) General Discussion how i used createFromXaml method parametre as xaml file

gerard1234

Hello.

In this example you get Techy from an xaml file.

Does anyone know how remove this Techy and replace it with another xaml file

The idee is that you've got frames for example: left , top , main.

The left and top stay the same, but the main changed when you push on a button,

when you've 4 buttons, each of the buttons belong to an xaml file. and this file wil be loaded into the main frame.

I've got this code:

var TechyPicture= root.findName("Techy");
canvas.children.remove(TechyPicture);

But then I can just delete 1 xaml file all the time and when it does'nt excist you get warnings.

So I hope someone hase an example for me with this function.

I hope you understand my question and have an answer.

bye





Re: Silverlight (formerly WPF/E) General Discussion how i used createFromXaml method parametre as xaml file

gerard1234

Hello Denish.

Do you've got it working what you want and don't you get errors when you download a xaml file please let me know, because I want the same as what you posted.

bye