【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 一般软件和游戏有多窗口多界面时,都可以拖动子界面和排序子界面[点击后变成焦点界面显示在最前面] ...
随机推荐
- HTML5 CANVAS 弹幕插件
概述 修改了普通弹幕运动的算法,新增了部分功能 详细 代码下载:http://www.demodashi.com/demo/10595.html 修改了普通弹幕运动的算法,新增了部分功能,具体请参看附 ...
- CSS3饼状loading效果
概述 之前看到很多饼状loading效果是用图片的方式实现的,本例子采用的是纯CSS3实现,这样可以节省资源空间,有兴趣的小伙伴可以看下~ 详细 代码下载:http://www.demodashi.c ...
- Android网络开发之Socket通信
HTTP通信中Client发送的每次请求都需要Server回送响应,在请求结束后,Client会主动释放连接.从建立连接到隔壁连接的过程成为一次连接.要保持Client程序的在线状态,需要不断地向Se ...
- PHP反射获取当前函数的内容
<?php $test = function () { echo 'hello world'; }; function closure_dump($closure) { try { $func ...
- mysql sleep连接太多怎么办
摘要:interactive_timeout和wait_timeout参数对sleep连接的影响 interactive_timeout 参数含义:服务器关闭交互式连接前等待活动的秒数.交互式客户端定 ...
- HDUOJ---(4708)Herding
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 【LeetCode】164. Maximum Gap (2 solutions)
Maximum Gap Given an unsorted array, find the maximum difference between the successive elements in ...
- 【js】appendChild
appendChild主要是用来追加节点插入到最后:循环的时候由于不停的搬家导致length在改变. 使用for循环 <!Doctype html> <html xmlns= ...
- PLSQL_标准游标类型的解析(概念)
2014-06-02 Created By BaoXinjian
- Eclipse编译快捷键
从C#转学Java,总结了一些Eclipse跟Microsoft Visual Studio 向对应的快捷键: 1. Run Ctrl+F11 (VS对应的是F5) 2. Debug F11 ( ...