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

Source: Internet
Author: User
Tags silverlight

C # development Wpf/silverlight animation and games series Tutorials (Game Tutorial): (42) make exquisite mini map ②

The previous chapters include the Object Avatar Panel, mini radar maps and other forms are fixed position, in a variety of ways and simple, and RPG, SLG, leisure and other types of games are often used in a large number of suspension and can be freely drag the form, such as the package Panel, Weapon Equipment Panel, personal properties panel, Skills Panel, System Setup Panel, and so on, which requires us to tailor a generic and easy-to-use ChildWindow control to the game. So in this section I'll show you how to make a custom ChildWindow control with a high degree of freedom to drag the head, close the button, and the content body 3 large parts, and use it to implement the mini path map.

First of all, we need to determine the functional requirements of the ChildWindow, from the layout of the above 3, and these 3 parts can be implemented with any object, so as to achieve a high degree of expansion; functionally, ChildWindow can be dragged arbitrarily in the game window, and a number of ChildWindow instances there is also a coordinated hierarchical relationship, this aspect of the content you can refer to my another article on ChildWindow, from the overall structure, ChildWindow can be with the game with the object of easy interaction, It also does not affect the activities of other objects in the game.

Then go to the actual design phase, at which point we have 3 ways to choose:

1) through the underlying inheritance to achieve. For example, create a new BaseWindow.cs class file, and then let it inherit control or ContentControl or UserControl and so on, and add and layout the various parts by code, while implementing the functions of each part of the event, and finally let This.content = Total layout control or other way to complete the definition of the base class. Other controls can then extend the specific functionality of each individual control by inheriting the Basewindow and then having all the Basewindow functions. In general, this is a traditional solution, but it is not easy to use in wpf/silverlight, because there is a layer of XAML, and most developers do not necessarily have the underlying control development technology and experience, it is difficult to achieve.

2) through the Silverlight template control to implement. Many Silverlight developers abroad prefer to use this approach for control development. Concrete steps: Right-click on the project-> add-> New Item->silverlight templated control:

New good, you can see the project structure appeared in a themes folder, and inside the bread contains a template file called Generic.xaml, the main code is as follows:

<Style TargetType="local:QXChildWindow">
 <Setter Property="Template">
  <Setter.Value>
   <ControlTemplate TargetType="local:QXChildWindow">
     ……模板内容……
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>

Later, if a new template is added to the project, the XAML portions of all the templates are appended to the file in such a format, except that they are bound in targettype different (CS files):

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.