C # development Wpf/silverlight animation and games series Tutorials (Game Tutorial): (39)

Source: Internet
Author: User
Tags visibility silverlight

C # development Wpf/silverlight animation and games series (Game Tutorial): (39) to Silverlight transplant ①

First, the main improvements:

1) Silverlight3.0 on the right key implementation:

//注册右键事件
HtmlPage.Document.AttachEvent("oncontextmenu", Game_MouseRightButtonDown);
//鼠标右键事件
private void Game_MouseRightButtonDown(object sender, HtmlEventArgs e) {
        e.PreventDefault(); //取消右键弹出菜单
……逻辑部分
}

The above method must also be matched with <param name= "windowless" value= "true"/> or System.Windows.Interop.Settings.Windowless = True to achieve the right key function. It is also necessary to note that this approach is not an official solution, but rather a third-party indirect implementation. Therefore, before using, you must solve the cost of the Silverlight lifting right button: ①windowless = True lowers the overall performance of the program; ② cannot use IME; ③ is not compatible with all browsers, for example, in Google Chrome, Although the right key function can be stimulated, but the pop-up right-click menu will not be canceled. In summary, in the Silverlight3.0, you still have to carefully consider whether to use the right button.

2 The Undo Wizard and all other controls in the X,y,z coordinate positioning with the associated property, replaced by a named Coordinate association property, its complete definition is as follows:

///<summary>
///Gets or sets control coordinates (association properties)
///</summary>
Public point coordinate {
Get {RET Urn (point) GetValue (Coordinateproperty);
Set {SetValue (Coordinateproperty, value);}
}
public static readonly DependencyProperty Coordinateproperty = dependencyproperty.register (
"coordinate" ,
typeof (Point),
typeof (Qxsprite),
New PropertyMetadata (Changecoordinateproperty)
);
Private static void Changecoordinateproperty (DependencyObject D, DependencyPropertyChangedEventArgs e) {
Qxsprite obj = (QXS Prite) D;
if (obj.   Visibility = = visibility.visible) {
Point P = (point) e.newvalue;
Obj. SetValue (Canvas.leftproperty, P.x-obj. CenterX);
obj. SetValue (Canvas.topproperty, P.y-obj. CenterY);
obj. SetValue (Canvas.zindexproperty, Convert.ToInt32 (P.Y));
}
}

The type of coordinate is point, so I replace the DoubleAnimation animation type used by the original sprite with PointAnimation, which is greatly optimized in both the code structure and the performance. When you change the coordinates of a control, you can simply modify its coordinate = new Point (x,y) to determine whether the value of the associated property has changed to trigger the Changecoordinateproperty method. This updates the control's final Leftproperty, Topproperty, and zindexproperty in the screen. Yes, the correlation attribute is so powerful.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.