有关Expander组件的研究——Silverlight学习笔记[33]
Expander组件常用做边栏目录的分类,比如Windows中“我的文档”的侧边栏。本文将为大家介绍该组件的基本特性以及实际应用。
组件所在命名空间:
System.Windows.Controls
组件常用方法:
OnCollapsed:当IsExpanded属性由true转变为false时,引发已闭合(Collapsed)事件。
OnExpanded:当IsExpanded属性由false转变为true时,引发已展开(Expanded)事件。
组件常用属性:
ExpandDirection:获取或设置该组件内容窗口的打开方向。
IsExpanded:获取或设置一个值用来表示该组件的内容窗口是否可见。
组件常用事件:
Collapsed:当该组件的内容窗口闭合且只有组件头部可见时发生。
Expanded:当该组件的内容窗口打开并且同时显示组件头部和内容窗口时发生。
实例:
说明:本实例还同时介绍该组件模板的自定义。
详细内容在代码注释中给出。
MainPage.xaml文件代码:
<UserControl
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"
mc:Ignorable="d" xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" x:Class="SilverlightClient.MainPage"
d:DesignWidth="320" d:DesignHeight="240">
<Grid x:Name="LayoutRoot" Width="320" Height="240" Background="White">
<controlsToolkit:Expander x:Name="sampleExpander" Margin="90,22,110,0" VerticalAlignment="Top" Width="120">
<!--Expander头部模板开始-->
<controlsToolkit:Expander.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="sidelist.png" Height="16" Width="16"/>
<TextBlock Text="头部" FontSize="14"/>
</StackPanel>
</DataTemplate>
</controlsToolkit:Expander.HeaderTemplate>
<!--Expander头部模板结束-->
<!--Expander内容模板开始-->
<controlsToolkit:Expander.ContentTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="Test Content 1"/>
<TextBlock Text="Test Content 2"/>
<TextBlock Text="Test Content 3"/>
</StackPanel>
</DataTemplate>
</controlsToolkit:Expander.ContentTemplate>
<!--Expander内容模板结束-->
</controlsToolkit:Expander>
<Border Height="54" Margin="146,0,8,8" VerticalAlignment="Bottom" BorderBrush="Black" BorderThickness="1">
<TextBlock x:Name="tbResult" Foreground="Red" FontSize="14" Margin="0,0,-2,-2" TextWrapping="Wrap"/>
</Border>
<Button x:Name="btnOpen" Height="25" HorizontalAlignment="Left" Margin="8,0,0,66" VerticalAlignment="Bottom" Width="63" Content="展开" FontSize="13.333"/>
<Button x:Name="btnClose" Height="25" HorizontalAlignment="Left" Margin="75,0,0,66" VerticalAlignment="Bottom" Width="63" Content="闭合" FontSize="13.333"/>
<ComboBox x:Name="cbExpandDirection" Height="25" FontSize="14" HorizontalAlignment="Left" Margin="8,0,0,8" VerticalAlignment="Bottom" Width="130"/>
<TextBlock Height="25" Margin="11,0,0,33" Text="展开方向:" TextWrapping="Wrap" FontSize="12" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="60"/>
<TextBlock Height="25" Margin="146,0,101,66" VerticalAlignment="Bottom" Text="事件结果:" TextWrapping="Wrap" d:LayoutOverrides="HorizontalAlignment" FontSize="13.333"/>
</Grid>
</UserControl>
MainPage.xaml.cs文件代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightClient
{
//定义辅助类
public class ExpanderDirectionHelper
{
public string ExpanderDirectionName { get; set; }
public ExpandDirection theDirection { get; set; }
}
public partial class MainPage : UserControl
{
List<ExpanderDirectionHelper> cbExpanderDirectionList = new List<ExpanderDirectionHelper>();
public MainPage()
{
InitializeComponent();
//注册事件触发
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
this.btnOpen.Click += new RoutedEventHandler(btnOpen_Click);
this.btnClose.Click += new RoutedEventHandler(btnClose_Click);
this.cbExpandDirection.SelectionChanged += new SelectionChangedEventHandler(cbExpandDirection_SelectionChanged);
this.sampleExpander.Expanded += new RoutedEventHandler(sampleExpander_Expanded);
this.sampleExpander.Collapsed += new RoutedEventHandler(sampleExpander_Collapsed);
}
void sampleExpander_Collapsed(object sender, RoutedEventArgs e)
{
tbResult.Text = "闭合事件发生!";
}
void sampleExpander_Expanded(object sender, RoutedEventArgs e)
{
tbResult.Text = "展开事件发生!";
}
void cbExpandDirection_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbExpandDirection.SelectedItem != null)
{
//设置Expander展开方向
sampleExpander.ExpandDirection = (cbExpandDirection.SelectedItem as ExpanderDirectionHelper).theDirection;
}
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
//cbExpandDirection填充内容准备
cbExpanderDirectionList.Add(new ExpanderDirectionHelper() { ExpanderDirectionName = "上", theDirection = ExpandDirection.Up });
cbExpanderDirectionList.Add(new ExpanderDirectionHelper() { ExpanderDirectionName = "下", theDirection = ExpandDirection.Down });
cbExpanderDirectionList.Add(new ExpanderDirectionHelper() { ExpanderDirectionName = "左", theDirection = ExpandDirection.Left });
cbExpanderDirectionList.Add(new ExpanderDirectionHelper() { ExpanderDirectionName = "右", theDirection = ExpandDirection.Right });
cbExpandDirection.ItemsSource = cbExpanderDirectionList;
cbExpandDirection.DisplayMemberPath = "ExpanderDirectionName";
cbExpandDirection.SelectedIndex = 1;
}
void btnClose_Click(object sender, RoutedEventArgs e)
{
sampleExpander.IsExpanded = false;
}
void btnOpen_Click(object sender, RoutedEventArgs e)
{
sampleExpander.IsExpanded = true;
}
}
}
最终效果图:
文章出处:Kinglee’s Blog (http://www.cnblogs.com/Kinglee/)
版权声明:本文的版权归作者与博客园共有。转载时须注明本文的详细链接,否则作者将保留追究其法律责任。
有关Expander组件的研究——Silverlight学习笔记[33]相关推荐
- 有关Silverlight TabControl组件的研究——Silverlight学习笔记(5)
说明:通过对于Silverlight TabControl组件及其子组件TabItem的学习,您将了解到该组件能够有效充分地利用屏幕空间,并且能展示大量的数据内容,使得应用程序的内容布局更趋合理. [ ...
- 有关Rating组件的研究——Silverlight学习笔记[41]
我们经常能在网上发现为新闻.博客文章.图片或是电影视频的评分功能.在Silverlight中,使用Rating组件便能助我们完成以上的功能.本文将为大家介绍该组件的基础知识以及自定义应用方面等方面的内 ...
- 有关Silverlight浮动窗体组件的研究——Silverlight学习笔记(3)
说明:Silverlight的ChildWindow组件给我们的开发带来了便利,比如说我们可以用它开发自定义对话框等.然而,这同时也带来了这样一个问题,ChildWindow组件只能以Modal Wi ...
- 有关Data Input类组件的研究——Silverlight学习笔记[26]
Data Input(数据输入)类在Silverlight的应用中是十分常见的.Data Input类组件共有三个组件构成:DescriptionViewer(描述显示).Label(标签)以及Val ...
- 有关Accordion组件的研究——Silverlight学习笔记[27]
Accordion组件在开发中常用于信息的分类显示.本文将为大家介绍该组件的特性以及通过一个实例讲述该组件的基本运用. 组件所在命名控件: System.Windows.Controls 组件常用方法 ...
- 有关DataVisualization类组件的研究——Silverlight学习笔记[43]
Data Visualization类组件以直观的图表方式显示数据的分布,能够让我们更好地分析各数据的内在联系.本文主要向大家介绍该类组件的基本特性以及使用实例. 一.基本特性介绍 1.chart组件 ...
- 有关Navigation的研究——Silverlight学习笔记[29]
在Silverlight的程序设计中经常需要在多个XAML页面之间进行切换,以进行不同的功能操作.Silverlight为我们提供了一组控件以实现这一功能.本文将为大家介绍如何在Silverlight ...
- 强大的DataGrid组件[4]_实现CURD[上]——Silverlight学习笔记[12]
在本教程中,主要为大家讲述如何使用DataGrid来对后台数据库进行CURD操作.由于CURD操作是与数据库交互中最为常用的,因此掌握其使用方法就显得尤为必要.本教程将使用Linq to SQL Cl ...
- vs2010 学习Silverlight学习笔记(8):使用用户控件
概要: 这个类似于封装控件样式.不过封装的是整个或是多个控件罢了,然后用的时候就可以直接引用过来了. 创建用户控: 这个也很简单,不过有几个地方需要注意下.这个就不照抄了,咱们也自己写一个. 步骤: ...
最新文章
- 多路径配置udev_ASM磁盘多路径及udev配置
- java设计模式简述
- 14.parfor并行循环处理
- linux ftp下载文件_Linux系统中10个使用Wget命令下载文件示例
- 金融系统中正确的金额计算及存储方式
- 揭秘2019双11背后的云网络 – 双11网络架构和洛神系统
- 搞懂这三个指标,数据分析起码少费一半力
- IOS开发--仿制网易新闻
- 精益质量管理之做好质量管理工作的三大管理手法
- c#实现文件转base64和base64转文件(文件为任意格式)
- sosoapi 项目之本地搭建
- c语言课程设计报告 数独,C语言课程设计报告数独.pdf
- word 转 html
- 安装windows server 2003两种授权模式之间的区别
- 2300. 咒语和药水的成功对数 ●●
- 2022百万奖金投委团 |香港科大-杰瑞集团 2022【人工智能】百万奖金国际创业大赛...
- 从零开始,耗时两年,19岁小伙自制一块32位Risc-V处理器,可玩「贪吃蛇」
- matlab 冒号范围,MATLAB中冒号的用法
- 决策的五个要素(卓有成效的管理者)
- STM32 HAL库PID控制电机 第二章 TB6612FNG芯片驱动GB37-520电机
热门文章
- 2020-10-18C++笔记之C/C++之字符串赋值
- Docker(十四):Docker:网络模式详解
- sqlite3自增key设定(创建自增字段)
- 阿里二面,原来我对自动化测试的理解太浅了
- 还在加班做数据吗?今天1分钟教你学会用Python轻松玩转Excel
- python输入是什么类型_python入门04——输入输出
- CodeIgniter类库
- 饥荒海难机器人怎么用_饥荒海难机器人作用详解 机器人有什么用
- php 小数末尾进1,PHP处理浮点数进一、去尾(不进行四舍五入) | 剑花烟雨江南...
- linux7.4安装语言包,CentOS 7.4安装时报错最简单最直接的解决办法