欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
WPF Event & Command 之一:Event
Event & Command
Event 和Command是程序內部通信的基礎。Routed events 能夠發(fā)起多重控件,并且能有序和用戶(hù)輸入溝通。Commands是.NET Framework提供的核心構架,來(lái)激活和去激活高級別任務(wù)。Animation是events的更進(jìn)一步,讓你能夠以友好交互的方式使用event構架,來(lái)使用多重控件。
1.1. Configuring Events and Event Handling
routed event architecture 是WPF中比較特殊的Event構架,和其他技術(shù)中Event事件不同。routed event讓從某個(gè)control中定義event,能夠被這個(gè)control的父control所發(fā)起。例如:一個(gè)在toolbar中的button control可以被button, toolbar, grid, window 發(fā)起。
應用情景:一個(gè)計算器程序,某些BUTTON可以有自己的獨特的作用,但是有一個(gè)需求,在點(diǎn)擊某個(gè)控件時(shí),所有的BUTTON都需要有同一個(gè)click Event,為了少寫(xiě)些代碼,可以用這個(gè),只要在一個(gè)地方寫(xiě)click Event,所有在這個(gè)Windows里的button都可以有這個(gè)click event.
1.2. Types of Routed Events 種類(lèi)
l direct, bubbling, and tunneling
l Direct events是最像普通.net事件的。是有其定義的control發(fā)起,其他control不能控制它,例如:MouseLeave event.
l Bubbling events是從子控件開(kāi)始,逐步影響所有的父控件。例如MouseDown依次從Label,FlowPanel,window 逐步raised。所有控件都可以做Bubbling events
l Tunneling events 和Bubbling Events完全不同,他是先從最高層父控件開(kāi)始,逐步影響其集成關(guān)系的控件,最后到其定義子控件。例如:PreviewMouseDown。Tuneling event can let you intercept and handle the event, so you can filter input ,例如:keystrokes
l 所有的Tunneling Event都以Preview開(kāi)頭,例如 PreviewKeyDown,PreviewMouseDown。Tunneling Event都是和bubbling Event成對被定義,例如:PreviewKeyDown和KeyDown是一起出現。這個(gè)造成了 Tunneling Event和他的結對Bubbling Events共享了事件實(shí)例中的參數。
1.3. RoutedEventArgs參數
Handled
Indicates whether this event has been handled. By setting this property to True, you can halt further event bubbling or tunneling
OriginalSource
Returns the RoutedEvent object for the event that was raised. When handling more than one event with the same event handler, you might need to refer to this property to identify which event has been raised.
RoutedEvent
RoutedEventArgs
Source
Returns the object that raised the event.
1.3.1. Attaching an Event Handler
l 在XAML中attaching an Event Handler
l 在C#中寫(xiě)這個(gè)function
private void BtnMultiply_Click(object sender, RoutedEventArgs e)
{
}
1.3.2. Attached Events
l 在父元素中定義一個(gè)子元素的event,叫做Attached Events
1.3.3. Handling a Tunneling or Bubbling Events
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}
Tunneling events和Bubbling events(例如PreViewkeyDown和KeyDown)共享了RoutedEventArgs的實(shí)例。如果把Tunneling Event的Handled參數設置成true,其對應的bubbling event也同樣是抑制處理。
1.4. The EventManager Class 事件管理類(lèi)
EventManager is a static class that manages the registration of all WPF routed events.
public static class EventManager
繼承關(guān)系
System.Object   System.Windows.EventManager
Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)
Name
Description
GetRoutedEvents
Returns identifiers(an array) for routed events that have been registered to the event system.
GetRoutedEventsForOwner
Finds all routed event identifiers(an array) for events that are registered with the provided owner type.
RegisterClassHandler(Type, RoutedEvent, Delegate)
Registers a class handler for a particular routed event.
RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean)
Registers a class handler for a particular routed event, with the option to handle events where event data is already marked handled.
RegisterRoutedEvent
Registers a new routed event with the Windows Presentation Foundation (WPF) event system.
下面講事件類(lèi)怎么用:
1.4.1. Defining a New Routed Event 定義新的路由事件
1.       創(chuàng )建一個(gè)static, read-only definition for the event
public static readonly RoutedEvent SuperClickEvent;
2.       創(chuàng )建一個(gè) wrapper for the routed event that exposes it as a traditional .NET Framework event
public event RoutedEventHandler SuperClick
{
add
{this.AddHandler(SuperClickEvent, value);}
remove
{this.RemoveHandler(SuperClickEvent, value);}
}
自RoutedEventArgs使用EventArgs類(lèi)。必須從RoutedEventArgs派生一個(gè)新類(lèi),并創(chuàng )建一個(gè)新的委托,使用這些事件參數。
3.       使用EventManager來(lái)在類(lèi)構架中注冊一個(gè)新事件來(lái)包含這個(gè)事件。必須提供the name of the event, the routing strategy (direct, tunneling,or bubbling), the type of delegate that handles
EventManager.RegisterRoutedEvent("SuperClick",RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Window1));
1.4.2. Raising an Event 發(fā)生一個(gè)事件
在事件定義之后,你能夠發(fā)起一個(gè)RoutedEventArgs的新實(shí)例(使用RaiseEvent方法)
RoutedEventArgs myEventArgs = new RoutedEventArgs(myControl.myNewEvent);
RaiseEvent(myEventArgs);
1.4.3. Creating a Class-Level Event Handler 創(chuàng )建Event Handler
使用EventManager的類(lèi)注冊a class-level event handler,這個(gè)類(lèi)級別的Event handler在整個(gè)類(lèi)的實(shí)例中處理特定的event,通常在instance handlers之前invoke.因此可以在Instance handlers之前,清理和制止event。
1.       Create a static method to handle the event. This method must have the same signature as the event.
private static void SuperClickHandlerMethod(object sender, RoutedEventArgs e)
{
// Handle the event here
}
2.       In the static constructor for the class for which you are creating the class-level event handler, create a delegate to this method.
RoutedEventHandler SuperClickHandler = new RoutedEventHandler(SuperClickHandlerMethod);
3.       Also in the static constructor, call EventManager.RegisterClassHandler to register the class-level event handler,.
EventManager.RegisterClassHandler(typeof(Window1),
SuperClickEvent,SuperClickHandler);
1.5. Application-Level Events 應用級別事件
每一個(gè)WPF應用都被Application 對象所包圍,提供了一組事件和應用的生命周期相關(guān)。你能夠處理這些events來(lái)執行代碼,響應應用的startup和closure。應用提供了一組事件,這些事件和頁(yè)面的瀏覽相關(guān)
Event
Description
Activated
Occurs when you switch from another application to your program. It also is raised the first time you show a window.
Deactivated
Occurs when you switch to another program
DispatcherUnhandledException
Raised when an unhandled exception occurs in your
application. You can handle an unhandled exception
in the event handler for this event by setting the
DispatcherUnhandledExceptionEventArgs.Handled
property to True.
Exit
Occurs when the application is shut down for any reason
SessionEnding
Occurs when the Windows session is ending, such as when the user shuts down the computer or logs off
Startup
Occurs as the application is started.
應用事件是標準的.NET事件(和routed event)相比,可使用標準的方法穿件應用事件。見(jiàn)下:
1.      在Visual Studio中,在Solution Explorer中,右擊Application.xaml(或者APP.xaml),查看代碼。
2.      在C#中創(chuàng )建Startup方法,來(lái)處理事件
void App_Startup(object sender, StartupEventArgs e)
{
// Handle the event here
}
3.      在XAML中,為Application加上事件句柄定義:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml" Startup="App_Startup">
PRACTICE
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
閑話(huà)WPF之二十(WPF中的傳遞事件 [2] )
WPF中的傳遞事件
/linux/input.h
Linux input子系統分析
Input Core和evdev基本知識 - Kernel3.0.8 .
Scheduler,Handler和Event類(lèi)的關(guān)系
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久