如何将一个wpf窗体作为MDI子窗体在MDI父窗体中显示? C#中如何将一个WPF窗体作为MDI子窗体在MDI父窗体中显示? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一步. 建一个MainWindow.xaml 的窗体作为主窗体XAML:<DockPanel HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto" MinWidth="500" MinHeight="200"> <GroupBox DockPanel.Dock="Left" Width="100" Height="Auto" Header="Menu"> <StackPanel> <Button x:Name="Child1" Tag="Child1" Content="子窗体1" Margin="3" Click="Child1_Click"/> <Button x:Name="Child2" Tag="Child2" Content="子窗体2" Margin="3" Click="Child2_Click"/> <Button x:Name="Child3" Tag="Child3" Content="子窗体3" Margin="3" Click="Child3_Click"/> </StackPanel> </GroupBox> <GroupBox x:Name="ChildrenWinWrapper" DockPanel.Dock="Top" Height="Auto" MinWidth="400" HorizontalAlignment="Stretch" Width="Auto"> <DockPanel x:Name="ChildrenWinContent" HorizontalAlignment="Stretch" Width="Auto"> </DockPanel> </GroupBox> </DockPanel>CS: private Dictionary<string, UserControl> _userControls = new Dictionary<string, UserControl>(); public Dictionary<string, UserControl> GetUserControls() { return _userControls; } public Window1() { InitializeComponent(); List<string> userControlKeys = new List<string>(); userControlKeys.Add("Child1"); userControlKeys.Add("Child2"); userControlKeys.Add("Child3"); Type type = this.GetType(); Assembly assembly = type.Assembly; foreach (string userControlKey in userControlKeys) { string userControlFullName = String.Format("{0}.AppPages.{1}", type.Namespace, userControlKey); UserControl userControl = (UserControl)assembly.CreateInstance(userControlFullName); _userControls.Add(userControlKey, userControl); } //打开默认子窗体 Child1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } private void Child_Click(object sender, RoutedEventArgs e) { ChildrenWinContent.Children.Clear(); Button button = (Button)e.OriginalSource; ChildrenWinWrapper.Header = button.Content; Type type = this.GetType(); Assembly assembly = type.Assembly; ChildrenWinContent.Children.Add(_userControls[button.Tag.ToString()]); } 第二步: 在解决方案内创建一个AppPages文件夹,在文件夹里创建3个usercontrol,分别为Child1.xaml,Child2.xaml,Child3.xaml 运行程序,就可以实现MDI窗体的效果了!本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/soft2buy/archive/2010/04/13/5479946.aspx 这种方法我清楚,但是我是希望将wpf窗体作为mdi子窗体放在普通的form窗体中 CellFormatting 不统计Visible=false的单元格么? 关键字变色 treeView 50分关于权限的问题 DataGridView能否合并某行中几个连续的Cell? 请问如何将一个负数转换成一个8位的byte? 100分求救:关于输入数字的限制和对话框的问题(顶者有分,分不够可再加) 大家支持一下,收集jacaScript脚本——谢谢! 求解:基于流输入错误 C#新手多线程求助 正则表达式 在线等 求助 问个问题listview怎么把一列的值相加
<StackPanel>
<Button x:Name="Child1" Tag="Child1" Content="子窗体1" Margin="3" Click="Child1_Click"/>
<Button x:Name="Child2" Tag="Child2" Content="子窗体2" Margin="3" Click="Child2_Click"/>
<Button x:Name="Child3" Tag="Child3" Content="子窗体3" Margin="3" Click="Child3_Click"/>
</StackPanel>
</GroupBox> <GroupBox x:Name="ChildrenWinWrapper" DockPanel.Dock="Top" Height="Auto" MinWidth="400" HorizontalAlignment="Stretch" Width="Auto">
<DockPanel x:Name="ChildrenWinContent" HorizontalAlignment="Stretch"
Width="Auto">
</DockPanel>
</GroupBox> </DockPanel>CS: private Dictionary<string, UserControl> _userControls = new Dictionary<string, UserControl>(); public Dictionary<string, UserControl> GetUserControls()
{
return _userControls;
} public Window1()
{
InitializeComponent(); List<string> userControlKeys = new List<string>();
userControlKeys.Add("Child1");
userControlKeys.Add("Child2");
userControlKeys.Add("Child3");
Type type = this.GetType();
Assembly assembly = type.Assembly;
foreach (string userControlKey in userControlKeys)
{
string userControlFullName = String.Format("{0}.AppPages.{1}", type.Namespace, userControlKey);
UserControl userControl = (UserControl)assembly.CreateInstance(userControlFullName);
_userControls.Add(userControlKey, userControl);
} //打开默认子窗体
Child1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
private void Child_Click(object sender, RoutedEventArgs e)
{
ChildrenWinContent.Children.Clear();
Button button = (Button)e.OriginalSource;
ChildrenWinWrapper.Header = button.Content;
Type type = this.GetType();
Assembly assembly = type.Assembly; ChildrenWinContent.Children.Add(_userControls[button.Tag.ToString()]);
} 第二步: 在解决方案内创建一个AppPages文件夹,在文件夹里创建3个usercontrol,分别为Child1.xaml,Child2.xaml,Child3.xaml 运行程序,就可以实现MDI窗体的效果了!本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/soft2buy/archive/2010/04/13/5479946.aspx
这种方法我清楚,但是我是希望将wpf窗体作为mdi子窗体放在普通的form窗体中