Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a main window named MainWindow.xaml.c and supporting XAML file MainWindow.xaml I just want to select different XAML file during run time depends upon some button click event. ie Mainwindow.xaml define a Datagrid with certain style and link to certain database. this has to be activated based on button1 click. if i click button2 it should corresponds to some other XAML file (eg:MainWindow2.xaml) which give different look.

how I can approach this problem

please somebody help me

Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jan-12 12:46pm    
Why doing so?
--SA

1 solution

It is not working that way :)
You also don't have to create a second window if you just want to change the look and feel.

Design your MainWindow and put your styles into a ResourceDictionary. Then you can apply the according style depending on a button click-event.

Have a look at the style class[^] or the styling and templating documentation[^].
 
Share this answer
 
Comments
[no name] 16-Jan-12 11:45am    
can anybody please give a small example of putting into a resource dictionary and how the respective dictionaries will be called on the button click event
SvenMe 16-Jan-12 11:49am    
Actually that's why I gave you the two links. The second one is showing exactly what you are asking for ^^
[no name] 16-Jan-12 12:40pm    
not only I want to retain the style of the control . iwant to use some other xaml file based on th button click.ie if button1 clicked abc.xaml will be linked with XXX.xaml.c if button to clicked def.xaml will be linkrd with XXX.xaml.c is there any such option in WPF
Sergey Alexandrovich Kryukov 16-Jan-12 12:50pm    
You cannot request "I want to use some other XAML file" in a productive way, because you mess up the question with your idea of the solution. You should address it separately. First, explain your ultimate goals, what application should do and why, without any preoccupation with any ideas on how you want to do it.
--SA
Sergey Alexandrovich Kryukov 16-Jan-12 12:47pm    
This is reasonable, my 5. Only OP if too far from all that, but it's hard to help in a quick answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900