【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 一般软件和游戏有多窗口多界面时,都可以拖动子界面和排序子界面[点击后变成焦点界面显示在最前面] ...
随机推荐
- 从零开始学做微信小程序,看这些就够了!
随着正式开放公测,微信小程序再次万众瞩目,越来越多的企业和个人涌入到小程序开发的大军中.小程序究竟是什么?适合做小程序的产品有哪些?做小程序需要提前准备什么?如何零基础学做小程序?此文,将列出OSC上 ...
- IT忍者神龟之 oracle行转列、列转行
一.行转列 须要将例如以下格式 转换为: 这就是最常见的行转列,主要原理是利用decode函数.聚集函数(sum).结合group by分组实现的 create table test( id varc ...
- 那些遇到的position-fixed无效事件
本篇文章由:http://xinpure.com/position-fixed-encountered-an-invalid-event/ 第一次无效事件 事件主角: transform 应用环境: ...
- PC端轻松控制Android手机,PC Control Andoroid,PC控制安卓手机
记录此次经历的目的是帮助需要的人或下次使用时少走弯路,我为此试用了不少工具及方法,因为追求免费,像"Weak Control:在PC上控制你的Android手机"还要收费的我就不弄 ...
- eclipse 无代码自动提示
http://blog.csdn.net/wgw335363240/article/details/6235427eclipse 无代码提示,显示No Default Proposals,Conten ...
- ubuntu 安装php-redis
sudo apt-get install redis-server 测试redis是否安装成功:注意:要开启redisredis-cliset test helloOKget test"ba ...
- Android 应用开发者必看的 9 个 Tips
去年,Android应用数量已经超过iOS成为全球最大的生态系统,不过在这多大百万的应用中,有些应用的下载量很大,赚的盆满钵满:另外一些应用就石沉大海.无人问津了. 拥有多年程序开发经验,最近在开发A ...
- PowerDesigner删除外键关系,而不删除外键列[转]
PowerDesigner中配置外键关系时,如果要删除配置的外键关系,默认设置会一同删除外键列. 要更改此设置,需在菜单栏tools中打开Model Options,在Model Settings中点 ...
- pythonl练习笔记——threading线程中的事件Event
1 事件Event 使用方法:e = threading.Event() Event对象主要用于线程间通信,确切地说是用于主线程控制其他线程的执行. Event事件提供了三个方法:wait等待.cle ...
- go 学习笔记(2) --变量、常量、iota、数组
参考网址:https://gobyexample.com 变量 Go中使用全新的关键字var来声明变量.var我们并不陌生,在Javascript 和C#中均有出现.不同的是Go和C#中变量属于强类型 ...