nguyenbinhking

Hi all,

I have a problem as following:

I have a xaml file, I want to read it on. After, I need to modify. Finally, I want to update and save it into database. Please give me some way to solve this my programma. I'm using Visual Studio 2005.

Thanhks all so much.




Re: Windows Presentation Foundation (WPF) How to read and write xaml from C# 2005.

Yi-Lun Luo - MSFT

Hello, you have two choices. First, since XAML is an Xml file, you can use standard Xml parsers such as SAX and DOM. Second, to make the job easy, you can use XamlReader and XamlWriter which will provide you with an object oriented method to deal with XAML files. But of course you can¡¯t use code behind for those files. Here¡¯s a sample:

Page page = (Page)XamlReader.Load(XmlReader.Create("TestXaml.xaml"));

StackPanel sp = (StackPanel)page.Content;

TextBox tb = new TextBox();

tb.Text = "abc";

sp.Children.Add(tb);

XamlWriter.Save(page, XmlWriter.Create("TestXaml.xaml"));

After this, you can use standard methods such as SqlCommand to modify database.






Re: Windows Presentation Foundation (WPF) How to read and write xaml from C# 2005.

nguyenbinhking

Hi Yi-Lun Luo,

Oh, yeah. I see your code. Thanks a lot. But Orcas which I'm using not support XamlWriter. What version Orcas are you using Please tell me know, Ok

Thanks again,






Re: Windows Presentation Foundation (WPF) How to read and write xaml from C# 2005.

Yi-Lun Luo - MSFT

As long as you have .NET 3.0 or higher installed, you should be able to use XamlWriter. It's under System.Windows.Markup namespace, PresentationFramework.dll. This has nothing to do with Visual Studio version. Well, I'm using Visual Studio 2008 Beta 2.






Re: Windows Presentation Foundation (WPF) How to read and write xaml from C# 2005.

Code Breaker

What if I have event handlers in the xaml file..This wont work right...is there any work around