用户控件(UserControl)
简介
"用户控件"继承自UserControl,而UserControl继承自ContentControl,也就是内容控件
UserControl和Window是一个层次上的,都有xaml和cs文件
流程
创建用户控件

写好用户控件
<UserControl x:Class="WpfDemo.UserControlDemo.OwnUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Label Content="这是一个用户控件"></Label>
<Slider Minimum="0" Maximum="100" Grid.Row="1"></Slider>
</Grid>
</UserControl>
用户控件也可以套用用户控件,组成更复杂的界面
<UserControl x:Class="WpfDemo.UserControlDemo.UseUserControlUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:userControlDemo="clr-namespace:WpfDemo.UserControlDemo"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Label Content="这是另一个用户控件,在这里使用了OwnUserControl用户控件"></Label>
<userControlDemo:OwnUserControl Grid.Row="1"></userControlDemo:OwnUserControl>
<Label Grid.Row="2" Content="这个用户控件在OwnUserControl的基础上再添加一个Slider"></Label>
<Slider Grid.Row="3" Minimum="0" Maximum="200" ></Slider>
</Grid>
</UserControl>
窗体引用用户控件
<Window x:Class="WpfDemo.UserControlDemo.UseUserControlWindow"
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:userControlDemo="clr-namespace:WpfDemo.UserControlDemo"
mc:Ignorable="d"
Title="UseUserControlWindow" Height="600" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="0.2*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Label Content="使用OwnUserControl用户控件"></Label>
<userControlDemo:OwnUserControl Grid.Row="1"></userControlDemo:OwnUserControl>
<Label Grid.Row="2" Content="使用UseUserControlUserControl用户控件"></Label>
<userControlDemo:UseUserControlUserControl Grid.Row="3"></userControlDemo:UseUserControlUserControl>
</Grid>
</Window>
示例代码
https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/UserControlDemo
用户控件(UserControl)的更多相关文章
- 用户控件UserControl图片资源定位(一)---Xaml引用图片
MEF编程实现巧妙灵活松耦合组件化编程,一些细节需要花费不小心思去处理: 其中组件中若包含用户控件,且需要访问图片资源,那么Xaml引用资源需要做以下设置 1. 用户控件(usercontrol)所在 ...
- asp.net动态解析用户控件(UserControl)
模块化的时候需要用到: #region asp.net解析用户控件 /// <summary> /// asp.net 解析用户控件 /// </summary> /// &l ...
- Windows.Forms Panel 动态加载用户控件 UserControl
创建好一个Windows Forms程序,在创建好的程序中Form1添加一个Panel控件 如图:
- C#中,用户控件UserControl里面用Panl加载UserControl,并实现利用委托互相传值
用户控件主窗体结构:左侧树形菜单,右侧Panl: 根据点击的菜单节点,panl里面选择性加载某一个子窗体用户控件,并传值给子窗体: 反之,在子窗体进行相应的操作之后,传值给主窗体,触发主窗体的刷新. ...
- 如何在组件(Component中)模拟用户控件(UserControl)中FindForm()?
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentM ...
- ASP.NET用户控件事件的定义和实践
假定用户控件(UserControl.ascx)中包含按钮控件 AButton,希望实现按 Button 按钮时,包含该用户控件的页面可以接收到事件. UserControl.ascx.cs ...
- WPF学习- AllowDrop 用户控件启用拖放功能
知识点: 创建自定义用户控件(UserControl) 使用户控件成为拖动源 使用户控件成为放置目标 使面板能够接收从用户控件放置的数据 创建项目: 1.新建WPF项目(Wpf-AllowDrop) ...
- 【WPF】WPF开发用户控件、用户控件属性依赖DependencyProperty实现双向绑定、以及自定义实现Command双向绑定功能演示
前言: Wpf开发过程中,最经常使用的功能之一,就是用户控件(UserControl)了.用户控件可以用于开发用户自己的控件进行使用,甚至可以用于打造一套属于自己的UI框架.依赖属性(Dependen ...
- wpf的UserControl用户控件怎么添加到Window窗体中
转载自 http://www.cnblogs.com/shuang121/archive/2013/01/09/2853591.html 我们来新建一个用户控件UserControl1.xaml &l ...
随机推荐
- Lucene学习总结之五:Lucene段合并(merge)过程分析 2014-06-25 14:20 537人阅读 评论(0) 收藏
一.段合并过程总论 IndexWriter中与段合并有关的成员变量有: HashSet<SegmentInfo> mergingSegments = new HashSet<Segm ...
- Linux下 kprobe工具的使用
此处转载: 一.Kprobe简单介绍 kprobe是一个动态地收集调试和性能信息的工具,它从Dprobe项目派生而来,是一种非破坏性工具,用户用它差点儿能够跟踪不论什么函数或被运行的指令以及一些异步事 ...
- svn: E200033: database is locked解决办法
svn执行update,却被告知database is locked! 执行 svn update,却抛出个错误警报: svn: E200033: database is locked, execut ...
- 30行js rem弹性布局适配所有分辨率
<script> /* # 按照宽高比例设定html字体, width=device-width initial-scale=1版 # @pargam win 窗口window对象 # @ ...
- 使用Opencv中均值漂移meanShift跟踪移动目标
Mean Shift均值漂移算法是无参密度估计理论的一种,无参密度估计不需要事先知道对象的任何先验知识,完全依靠训练数据进行估计,并且可以用于任意形状的密度估计,在某一连续点处的密度函数值可由该点邻域 ...
- cordova 生成发行版apk,并添加证书 – 畅玩Coding
原文:cordova 生成发行版apk,并添加证书 – 畅玩Coding 首先jdk生成证书. 1.进入jdk安装目录 D:\Java\jdk1.7.0\bin 2.执行命令 keytool -gen ...
- 常规容器下SpringBootServletInitializer如何实现web.xml作用解析
在之前的<使用jsp作为视图模板&常规部署>章节有过一个实践,需要启动类继承自SpringBootServletInitializer方可正常部署至常规tomcat下,其主要能够起 ...
- 1-5设定NetCore监听端口
问题的起源:启动一个.netCore项目,默认使用的是5000端口,当我们有很多个项目的时候(集群),不可能都使用5000端口. 方法1:set ASPNETCORE_URLS=http://127. ...
- 分类算法SVM(支持向量机)
支持向量机(Support Vector Machine ,SVM)的主要思想是:建立一个最优决策超平面,使得该平面两侧距离该平面最近的两类样本之间的距离最大化,从而对分类问题提供良好的泛化能力.对于 ...
- [OpenGL]OpenGL坐标系和坐标变换
OpenGL通过摄像机的模拟.要实现一个三维计算机图形重大转变,这是几何变换(模型转换-查看转型(两者统称为几何变换)).投影.作物转型.口变换等.同一时候,OpenGL还实现了矩阵堆栈等.理解掌握了 ...