"Miles Journey--windows App development" Control large collection 1

Source: Internet
Author: User

There are several ways to add controls. Which one do you like better?
1) Use design tools such as Blend for Visual Studio or Microsoft Visual Studio XAML Designer.
2) Add the control to the XAML markup in the Visual Studio XAML editor.
3) Add the control to the code. When the app executes, you'll see the controls you added to your code. However, it is not visible in the Visual Studio XAML Designer.

We've already used the grid, button, and so on, and now we have a systematic look at some of the properties, events, and so on of the control.

There is no doubt that the first step is to add controls, so what are the ways to add controls?

In the front we are all controls that are written directly in XAML or dragged out of the toolbox.

In fact there are 2 kinds, one is more complicated but we will use it later, that is to add the control in C # background code, and another is to drag the control in blend for Visual studio.

The latter function is also very powerful, for example, to use animation and the like, this designer can play a role.

The properties of the control are already used compared to the one that can be added directly to the XAML and the ability to add and change attributes in the Properties view.

Suppose you want to add and change events, the same in the Properties view, click the Lightning bolt icon in the upper-right corner. If you want to add the click event, simply press ENTER after you enter the event name in the input box of the click. At this point, VS will take its own initiative to jump to the C # backend code. The first parameter sender is the application of the object attached to the handler. The second parameter is the event data, which is typically displayed as an e parameter in the signature.

privatevoidbtnSetStyle_Click(object sender, RoutedEventArgs e){    Button b = (Button)sender;    400;    320;}

This code above will set the clicked button's height to 400, the width is set to 320, in addition to such a way, can also be as follows, for example, Btnsetstyle is the name of the current button:

privatevoidbtnSetStyle_Click(object sender, RoutedEventArgs e){    400;    320;}

In addition, we can not define the click event in XAML, which, for example, can achieve the same effect, and it associates two events with one another.

publicMainPage(){     this.InitializeComponent();     new RoutedEventHandler(btnSetStyle_Click);}privatevoidbtnSetStyle_Click(object sender, RoutedEventArgs e){    400;    320;}

We have already learned the assumption of adding controls, adding/changing attributes, adding/altering events. Also look at the style of the control. Although it is possible to think of CSS when it comes to style. Presumably everyone has played 2048, the game has a lot of squares, then the style of these squares will not be one to define it, of course not, can directly use the style of resources to locate all the button. In the back we will also practice how to write a 2048 small game.

Here is the style I wrote in 2048,

<Page.Resources> <StyleTargettype="button"> <Setter  Property="FontWeight" Value="Bold"/> <Setter  Property="FontSize" Value="Max"/> <Setter  Property="HorizontalAlignment" Value="Center"></Setter> <Setter  Property="VerticalAlignment" Value="Center"></Setter> <Setter  Property="Background" Value="Gray"></Setter> <Setter  Property="Width" Value=" the"></Setter> <Setter  Property="Height" Value=" the"></Setter> <Setter  Property="Template"> <Setter.Value> <controltemplate targettype="button"> <GridX:name="Grid" Background="Transparent"> <border x:name="Border"Width="{TemplateBinding Width}"height="{TemplateBinding Height}" Background="{TemplateBinding Background}"> <contentpresenter x:name="ContentPresenter"Contenttemplate="{TemplateBinding contenttemplate}"Content="{TemplateBinding Content}"Horizontalalignment="Center"Verticalalignment="Center"/> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style></Page.Resources>

But there is also a problem here, assuming that we have 10 button controls, but only 8 of them need to use these definitions. The other 2 want to use a control, what to do?

Defines a style as a resource. In fact, there are 2 ways.


One is to use the TargetType property of the style directly to define all the target controls.
There is one other than using the TargetType attribute. It is also possible to set the detailed style property with the x:key attribute, and then the detailed control of the mean explicit keyword StaticResource.

<Page.Resources> <StyleTargettype="button"> <Setter  Property="FontStyle" Value="Oblique"/> <Setter  Property="FontSize" Value="a"/> <Setter  Property="BorderBrush" Value="Green"/> <Setter  Property="BorderThickness" Value="5"/> <Setter  Property="Foreground" Value="Orange"/> <Setter  Property="Height" Value="a"/> <Setter  Property="Width" Value=" the"/> </Style> <Stylex:key="Otherstyle"Targettype="button"> <Setter  Property="FontStyle" Value="Italic"/> <Setter  Property="FontSize" Value="+"/> <Setter  Property="Foreground" Value="Lavender"/> <Setter  Property="Height" Value=" the"/> <Setter  Property="Width" Value=" the"/> <Setter  Property="Opacity" Value="0.2"/> </Style> </Page.Resources>

See the detailed results, in which the Opacity property is transparent.

We all know that classes can inherit, and styles can be inherited as well.

Although the content of this blog is less, but the more exciting content is still behind it. Thank you for your support!

Thank you for your visit and hope to help you.

You are welcome to watch or Collect, comment or praise.

To make this article get treatise and ask questions, reprint please indicate the source:
Http://blog.csdn.net/nomasp

"Miles Journey--windows App development" Control large collection 1

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.