【WPF/WAF】主界面(ShellWindow)引入别的界面布局
问题:主界面如果只用一个布局文件ShellWindow.xaml,会写得很大很臃肿。需要分为多个布局文件,然后由主界面引入。参考http://waf.codeplex.com/官方的BookLibrary案例,别人也是这么做的。
使用WPF Application Framework (WAF)框架新建的项目,将模板的分包结构如下:
需求:在主界面ShellWindow右侧是分页栏(TabControl),每个分页栏内容是一个单独的XAML布局文件。所以现在测试往主界面引入一个界面。完成后的效果应该是这样的:
根据WAF项目的结构,最后看起来是下下图那样,红框中是新增的文件。
由于篇幅有限,只提及几个关键点。完整流程点这里下载。
ShellWindow.xaml关键部分:
<!-- 右侧顶部分页栏/分组栏 -->
<TabControl x:Name="tabControl" DockPanel.Dock="Top" Margin="410,0,10,0" Height="300" VerticalAlignment="Top">
<TabItem Header="户型">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ContentControl Name="HouseTypeView" Content="{Binding ShellService.HouseTypeView}" Margin="10" Focusable="False"/>
</ScrollViewer>
</TabItem>
......
新建的分页栏某一页的布局HouseTypeView.xaml:
<UserControl
x:Class="WafApplication1.Presentation.Views.HouseTypeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:WafApplication1.Applications.ViewModels"
xmlns:local="clr-namespace:WafApplication1"
mc:Ignorable="d" MinWidth="300" MinHeight="270"
>
<DockPanel Margin="10" >
<StackPanel Orientation="Vertical">
<Grid Margin="10" Height="40" >
<!-- 定义列宽 -->
<Grid.ColumnDefinitions>
<!-- 第一列 -->
<ColumnDefinition Width="100"/>
<!-- 第二列 -->
<ColumnDefinition Width="200"/>
<!-- 第三列 -->
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<!-- 第一行第一列 -->
<ComboBox Grid.Column="0" Grid.Row="0" x:Name="cityComboxBox" Margin="50,10,0,200" Height="20"/>
<!-- 第一行第二列 -->
<ComboBox Grid.Column="1" Grid.Row="0" x:Name="communityComboxBox" Height="20" Margin="10,10,0,200" />
<!-- 第一行第三列 -->
<Button Grid.Column="2" Grid.Row="0" x:Name="searchBtn" Command = "{Binding AlertCommand}" Content="搜 索" VerticalAlignment="Center" Width="50" Height="20" Background="#0094ff" Margin="10,10,0,200"/>
</Grid>
<Grid Height="100">
<StackPanel Orientation="Horizontal" Margin="10, 10, 10, 10">
<TextBlock Text="热门搜索 :" FontSize="10" Margin="70,5,20,62" HorizontalAlignment="Center" />
<WrapPanel Orientation="Horizontal" Width="250">
<TextBox Text="A社区" Margin="5" />
<TextBox Text="A社区" Margin="5" />
<TextBox Text="A社区" Margin="5" />
<TextBox Text="A社区" Margin="5" />
<TextBox Text="A社区" Margin="5" />
<TextBox Text="A社区" Margin="5" />
<TextBox Text="A社区" Margin="5" />
<TextBox Text="A社区" Margin="5" />
</WrapPanel>
</StackPanel>
</Grid>
</StackPanel>
</DockPanel>
</UserControl>
HouseTypeView.xaml.cs主要是做两个ComboBox下拉菜单的级联:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using WafApplication1.Applications.Views;
using WafApplication1.Applications.ViewModels;
namespace WafApplication1.Presentation.Views
{
[Export(typeof(IHouseTypeView))]
public partial class HouseTypeView : UserControl, IHouseTypeView
{
private Dictionary<string, string[]> cityAndCommunityDictionary = new Dictionary<string, string[]>()
{
{ "南宁", new string[] { "南宁A社区", "南宁B社区", } },
{ "柳州", new string[] { "柳州A社区", "柳州B社区", "柳州C社区", "柳州D社区" } },
{ "桂林", new string[] { "桂林A社区", "桂林B社区", "桂林C社区" } },
};
public HouseTypeView()
{
InitializeComponent();
// 初始化两个下拉列表
InitComboBox();
}
/// <summary>
/// 初始化选择城市的下拉列表
/// </summary>
private void InitComboBox()
{
// 初始化城市列表
ItemCollection coll = cityComboxBox.Items;
foreach (KeyValuePair<string, string[]> kvp in cityAndCommunityDictionary)
{
ComboBoxItem boxItem = new ComboBoxItem() { Content = kvp.Key };
coll.Add(boxItem);
}
// 给ComboBox注册一个选项改变的事件
cityComboxBox.SelectionChanged += new SelectionChangedEventHandler(cityComboxBox_SelectionChanged);
}
private void cityComboxBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// 当前城市的社区
ItemCollection coll = communityComboxBox.Items;
// 先清空
coll.Clear();
// 再添加
foreach (KeyValuePair<string, string[]> kvp in cityAndCommunityDictionary)
{
// kvp.Value = { "南宁A社区", "南宁B社区", }
// 此时的 cityComboxBox.SelectedValue = System.Windows.Controls.ComboBoxItem: 南宁
// 所以如果用这种方法获取选中的值,还需要切割字符串
ComboBoxItem selectedCity = cityComboxBox.SelectedItem as ComboBoxItem;
string cityName = selectedCity.Content.ToString();
System.Console.WriteLine("cityName = " + cityName);
if (cityName.Equals(kvp.Key))
{
foreach (var item in kvp.Value)
{
// item = "南宁A社区"
ComboBoxItem boxItem = new ComboBoxItem() { Content = item };
coll.Add(boxItem);
}
}
}
}
}
}
在Applications/Controllers新建一个HouseTypeController.cs:
using System.ComponentModel.Composition;
using WafApplication1.Applications.Services;
using WafApplication1.Applications.ViewModels;
namespace WafApplication1.Applications.Controllers
{
[Export]
internal class HouseTypeController
{
private readonly IShellService shellService;
private readonly HouseTypeViewModel houseTypeViewModel; // 引入
[ImportingConstructor]
public HouseTypeController(IShellService shellService, HouseTypeViewModel houseTypeViewModel)
{
this.shellService = shellService;
this.houseTypeViewModel = houseTypeViewModel; // 构造传参引入
}
public void Initialize()
{
shellService.HouseTypeView = houseTypeViewModel.View; //
}
}
}
修改Applications/Controllers/ApplicationControl.cs:
using System.ComponentModel.Composition;
using WafApplication1.Applications.Services;
using WafApplication1.Applications.ViewModels;
namespace WafApplication1.Applications.Controllers
{
[Export]
internal class ApplicationController
{
private readonly ShellService shellService;
private readonly ShellViewModel shellViewModel;
private readonly HouseTypeViewModel houseTypeViewModel;
private readonly HouseTypeController houseTypeController;
[ImportingConstructor]
public ApplicationController(ShellViewModel shellViewModel, ShellService shellService, HouseTypeViewModel houseTypeViewModel, HouseTypeController houseTypeController)
{
this.shellViewModel = shellViewModel;
this.shellService = shellService;
this.houseTypeViewModel = houseTypeViewModel;
this.houseTypeController = houseTypeController;
}
public void Initialize()
{
shellService.ShellView = shellViewModel.View;
houseTypeController.Initialize();
}
public void Run()
{
shellViewModel.Show();
}
public void Shutdown()
{
}
}
}
【WPF/WAF】主界面(ShellWindow)引入别的界面布局的更多相关文章
- 【WPF/WAF】界面布局(View)文件的多层嵌套(Nest)
碎碎念:使用的是略冷门的Window Application Foundation(WAF)框架,搜到的都是WPF的UserControl用户控件的用法,实在蛋疼. 需求:主界面ShellWindow ...
- WPF系列教程——(一)仿TIM QQ界面 - 简书
原文:WPF系列教程--(一)仿TIM QQ界面 - 简书 TIM QQ 我们先来看一下TIM QQ长什么样,整体可以将界面分为三个部分 TIM QQ 1. 准备 阅读本文假设你已经有XAML布局的基 ...
- C# winform 打开主界面并关闭登录界面
在winform 界面编程中,我们有时候要在主界面打开之前先显示登录界面,当登录界面用户信息校验正确后才打开主界面,而这时登陆界面也完成使命该功成身退了. 目前有两种方法可实现: 方法1. 隐藏登录界 ...
- 界面设计技法之css布局
css布局之于页面就如同ECMAScript之于JS一般,细想一番,html就如同语文,css就如同数学,js呢,就是物理,有些扯远,这里就先不展开了. 回到主题,从最开始的css到如今的sass(l ...
- 如何在Winform界面中设计图文并茂的界面
在Winform里面,很多控件元素都是标准的,如图标.按钮.工具栏等等,所以一般设计标准的Winform界面比较快捷,但是往往这样的界面相对单调一些,特别在界面控件比较少的情况下,我们往往需要加入一些 ...
- Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 1.跳转到拨号界面,代码如下: 1)直接拨打 Intent intentPhone = new Intent ...
- linux直接启动到字符界面或从字符界面启动到图形化界面
修改/etc/inittab文件 将内容为:"id:5:initdefault"的行的数字5改为3,保存重启即可直接进入字符界面 PS:3和5分别表示运行级别 从字符界面启动到图形 ...
- Java图形界面学习---------简易登录界面
/** * @author Administrator * Java图形界面学习---------简易登录界面 * date:2015/10/31 */ import java.awt.BorderL ...
- UGUI(七)界面拖动和焦点界面
http://blog.sina.com.cn/s/blog_89d90b7c0102vj9e.html 一般软件和游戏有多窗口多界面时,都可以拖动子界面和排序子界面[点击后变成焦点界面显示在最前面] ...
随机推荐
- Spring(十二)使用Spring的xml文件配置方式实现AOP
配置文件与注解方式的有非常大不同,多了非常多配置项. beans2.xml <?xml version="1.0" encoding="UTF-8"? & ...
- HDUOJ--1159Common Subsequence
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 【C++】const成员函数
形式: 在成员函数后面加上const限定词,表示不会修改对象内容. 例如Circle类: class Circle { double r; public: Circle(double newr) { ...
- 【LeetCode】56. Merge Intervals
Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given ...
- 【LeetCode】64. Minimum Path Sum
Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...
- Linux命令-某个用户组下面的所有用户
groups 查看当前登录用户的组内成员 groups gliethttp 查看gliethttp用户所在的组,以及组内成员whoami 查看当前登录用户名 系统内有关组的信息放在/etc/group ...
- Https自签名证书认证及数据请求的封装
在WWDC 2016开发者大会上,苹果宣布了一个最后期限:到2017年1月1日 App Store中的所有应用都必须启用 App Transport Security安全功能.App Transpor ...
- Maven + Eclipse + Tomcat - 开启项目调试之旅(转载)
本文的读者需要拥有一些Maven基础知识和实践,如果没有,请直接绕过或者先看一些关于Maven教程,比如Juven翻译的<Maven权威指南>,google一下便知. 开门见山,首先抛出一 ...
- 管道读写规则和Pipe Capacity、PIPE_BUF
一.当没有数据可读时 O_NONBLOCK disable:read调用阻塞,即进程暂停执行,一直等到有数据来到为止. O_NONBLOCK enable:read调用返回-1,errno值为EAGA ...
- debian更新源时找不到公钥的解决办法
W: GPG error: http://mirrors.163.com jessie-updates InRelease: The following signatures couldn't be ...