Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > WinFX General

Vista - xaml resourcedictionary

 
 
Old 08-31-2006   #1 (permalink)
=?Utf-8?B?TGFuY2VN?=


 
 

xaml resourcedictionary

I am new to Xaml and want to create a simple Xaml file that can be used on a
windows or web app. I created a xaml file with a ResourceDictionary tag as a
root which contains a StackPanel tag that contains a button and a textbox. I
want to fill the content of the Page and the Window elements with the same
StackPanel in the ResourceDictionary Xaml file so both apps have the same
textbox and button. I have the following code in the Window constructor:
ResourceDictionary resDict = new ResourceDictionary();
Uri uriRes = new Uri("MyXaml.xaml", UriKind.Relative);

resDict.Source = uriRes;

foreach (object objResource in resDict.Values)
{
StackPanel stk = (StackPanel)objResource;
this.Content = stk;
}

This puts the textbox and button on the form, but I am unable to reference
either object in the code because it complains if I put the Name attribute in
the textbox or button tags in the ResourceDictionary Xaml file. I could get
to them with the code ((TextBox)((StackPanel)this.Content).Children[1]) but
this is not a generic solution and I won't be able to respond to their events.

How can I achieve a generic and reusable Xaml definition for a simple form?
Is this the right way or do I need to do something else. Is it possible to
achieve this with Xaml?

Please help.

Thanks,

My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46