我如何在运行时在WPF datagrid中添加不同的XAML文件 [英] how I can add different XAML file at run time in WPF datagrid

查看:60
本文介绍了我如何在运行时在WPF datagrid中添加不同的XAML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为MainWindow.xaml.c并支持XAML文件的主窗口MainWindow.xaml我只想在运行时选择不同的XAML文件,这取决于某些按钮单击事件.即Mainwindow.xaml定义具有特定样式的Datagrid并链接到特定数据库.这必须基于button1单击来激活.如果我单击button2,它应该与其他XAML文件(例如:MainWindow2.xaml)相对应,从而产生不同的外观.

我该如何解决这个问题

请有人帮我

在此先感谢

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

推荐答案

这种方式不起作用:)
如果您只想更改外观,也不必创建第二个窗口.

设计MainWindow并将样式放入ResourceDictionary.然后,您可以根据按钮的单击事件来应用相应的样式.

看看样式类 [模板文档 [
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[^].


这篇关于我如何在运行时在WPF datagrid中添加不同的XAML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆