WPF UserControl 的绑定事件、属性、附加属性
原文:WPF UserControl 的绑定事件、属性、附加属性
WPF UserControl里可供绑定的属性
/// <summary>
/// 重写基类 Margin
/// </summary>
public new Thickness Margin
{
get { return (Thickness)GetValue(MarginProperty); }
set { SetValue(MarginProperty, value); }
}
public new static readonly DependencyProperty MarginProperty = DependencyProperty.Register("Margin", typeof(Thickness), typeof(MirrorGrid), new FrameworkPropertyMetadata(new Thickness(0), new PropertyChangedCallback(OnMarginChanged)));
private static void OnMarginChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
{
((FrameworkElement)target).Margin = (Thickness)e.NewValue;
}
UserControl 里的事件路由
/// <summary>
/// 声明路由事件
/// 参数:要注册的路由事件名称,路由事件的路由策略,事件处理程序的委托类型(可自定义),路由事件的所有者类类型
/// </summary>
public static readonly RoutedEvent OnToolTipShowEvent = EventManager.RegisterRoutedEvent("OnToolTipShow", RoutingStrategy.Bubble, typeof(RoutedEventArgs), typeof(UserControl));
/// <summary>
/// 处理各种路由事件的方法
/// </summary>
public event RoutedEventHandler OnToolTipShow
{
//将路由事件添加路由事件处理程序
add { AddHandler(OnToolTipShowEvent, value,false); }
//从路由事件处理程序中移除路由事件
remove { RemoveHandler(OnToolTipShowEvent, value); }
}
路由事件
private void RoutedToolTipShow(RoutedEventArgs param)
{
param.RoutedEvent = OnToolTipShowEvent;
param.Source = this;
this.RaiseEvent(param);
}
控件附加属性
public abstract class AquariumServices : DependencyObject
{
public enum Bouyancy {Floats,Sinks,Drifts}
public static readonly DependencyProperty BouyancyProperty = DependencyProperty.RegisterAttached(
"Bouyancy",
typeof(Bouyancy),
typeof(AquariumServices),
new PropertyMetadata(Bouyancy.Floats)
);
public static void SetBouyancy(DependencyObject element, Bouyancy value)
{
element.SetValue(BouyancyProperty, value);
}
public static Bouyancy GetBouyancy(DependencyObject element)
{
return (Bouyancy)element.GetValue(BouyancyProperty);
}
}
WPF UserControl 的绑定事件、属性、附加属性的更多相关文章
- WPF的DataTrigger绑定自身属性
原文:WPF的DataTrigger绑定自身属性 <DataTrigger Binding="{Binding RelativeSource={RelativeSource self} ...
- [WPF]UserControl的MouseWheel事件触发
用户控件: <UserControl> <Grid> <TextBox x:Name="textBlock" HorizontalAlignment= ...
- WPF MultiBinding后台绑定动态属性 属性改变不调用Convert的问题
一开始的写法: MultiBinding mb = new MultiBinding(); Binding b1 = new Binding(); b1.ElementName = "tex ...
- WPF UserControl响应窗体的PreviewKeyDown事件
目的 在UserControl页面实现通过快捷键打开新建窗口 实现过程 监听Window窗体的PreviewKeyDown 其实,使用KeyDown事件也是可以的 页面代码 <Window x: ...
- WPF ----在UserControl的xaml里绑定依赖属性
场景:在定义wpf 用户控件的时候,希望使用时设置自定义的属性来改变用户控件里的状态或内容等. 下面直接上实例代码: 用户控件的后台代码,定义依赖属性 public partial class MyU ...
- 重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试
原文:重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试 [源码下载] 重新想象 Windows 8 Store ...
- 整理:WPF中应用附加事件制作可以绑定命令的其他事件
原文:整理:WPF中应用附加事件制作可以绑定命令的其他事件 目的:应用附加事件的方式定义可以绑定的事件,如MouseLeftButton.MouseDouble等等 一.定义属于Control的附加事 ...
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性
1.jQuery为动态添加的元素绑定事件:在1.7之后,添加了live()方法,1.9后又被移除,1.9中可用on()方法: $(function() { $('.btn').on('click', ...
- jQuery动态添加li标签并添加属性和绑定事件
代码如下: <%@page import="java.util.ArrayList"%> <%@ page language="java" c ...
随机推荐
- Nginx 设置,设置已经解析的域名,在nginx中没有定义相应server时的默认访问
https://blog.csdn.net/m_nanle_xiaobudiu/article/details/80785027
- Ajax之旅(二)--XMLHttpRequest
上文中提到的Ajax的异步更新.主要使用XMLHttpRequest对象来实现的,XMLHttpRequest对象能够在不向server提交整个页面的情况下,实现局部更新网页. 当页面所有载 ...
- 18、IIC总线驱动程序
i2c_s3c2410.c是内核自带dev层(adapt)驱动程序,知道怎么发收数据,不知道含义 在与i2c_s3c2410.c(在其probe函数中的s3c24xx_i2c_init函数会初始化ii ...
- [Vue] Preload Data using Promises with Vue.js and Nuxt.js
Nuxt.js allows you to return a Promise from your data function so that you can asynchronously resolv ...
- php生成唯一字符串
$units = array(); //循环生成好多个唯一字符串 for($i=0;$i<1000000;$i++){ $units[]=md5(uniqid(md5(microtime(tru ...
- 【35.43%】【hdu 4347】The Closest M Points
Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Others) Total Submissio ...
- 【63.73%】【codeforces 560A】Currency System in Geraldion
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- HDOJ 5001 Walk
概率DP dp[j][d] 表示不经过i点走d步到j的概率, dp[j][d]=sigma ( dp[k][d-1] * Probability ) ans = sigma ( dp[j][D] ) ...
- Mac下Android studio 之NDK配置教程(一)
Mac下Android studio 之NDK配置教程(一) 1.概述 近期项目全线转移到Mac下使用使用Android studio开发. 遇到关键代码封装到 ***native***层,此时在wi ...
- RSA算法原理(转)
如果你问我,哪一种算法最重要?我可能会回答“公钥加密算法”.因为它是计算机通信安全的基石,保证了加密数据不会被破解.你可以想象一下,信用卡交易被破解的后果. 进入正题之前,我先简单介绍一下,什么是”公 ...