Behavior
Behavior翻譯是行為
在WPF中Behavior的使用時必須引用Blend的程序集。
?C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.5\Libraries\System.Windows.Interactivity.dll
?System.Windows.Interactivity;
?
或者通過Nuget包管理來獲取。
?
現(xiàn)在來說說如果使用
behavior是行為,而這個行為是針對控件的。
就目前WPF添加行為的方式可以有附加屬性 附加事件 依賴屬性等方法。
就特性而言behavior和附加屬性很相似。
那么使用方式:
創(chuàng)建一個由Behavior<DependencyObject>所派生的類
創(chuàng)建依賴屬性(不用回調(diào)方法)
根據(jù)你想要的效果來重寫B(tài)ehavior的方法
在xaml中使用
而在xaml中則是
?
<Window x:Class="Beh.MainWindow"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:local="clr-namespace:Beh"xmlns:AT="http://schemas.microsoft.com/expression/2010/interactivity" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"><Grid><TextBox Margin="211,147,191,124"><AT:Interaction.Behaviors><local:ATCH BackRed="False" /></AT:Interaction.Behaviors></TextBox></Grid> </Window>?
轉(zhuǎn)載于:https://www.cnblogs.com/T-ARF/p/10464604.html
總結(jié)
- 上一篇: linux pkg解压工具,Pkg 1.
- 下一篇: SQL语句面试题整理-四年经验