"Miles Journey--windows App development" control large collection "patching"

Source: Internet
Author: User

Use design tools such as Blend for Visual Studio or Microsoft Visual Studio XAML Designer.
Add controls to XAML markup in the Visual Studio XAML editor.
Add the control in your code. When your app runs, you'll see the controls you added in your code, but not 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 different 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, a more complex, but we will also use later, that is, in C # background code to add the control, and another is to drag the control in the blend for Visual studio. The latter function is also very powerful, such as the use of animation and so on, this designer can play a role.

Control's properties are already in use, one can add properties directly to XAML, and you can add and modify properties in the Properties view.

If you want to add and modify events, also in the Properties view, click the Lightning bolt icon in the upper-right corner. If you want to add a click event, press ENTER directly after entering the event name in the input box of the click. At this point, vs will automatically jump to the C # background code, the first parameter sender is the application of the object attached to the handler, the second parameter is the event data, which is usually displayed as the e parameter in the signature.

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

This code above sets the height of the button clicked to 400 and the width to 320, and in addition to this, it can be done as follows, where 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, and the same effect can be achieved by doing the following, which associates two events with each other.

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

We've already learned that if you add controls, add/modify properties, add/Modify events. Also understand the style of the control, although it is possible to think of the style CSS. Presumably everyone has played 2048, the game has many many squares, then these squares style will not be one to define it, of course not, you can directly use the style resources to locate all the button. In the back we will also practice how to write a 2048 small game.

Here are the 2048 styles I wrote,

<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, if we have 10 button control, but only 8 of them to use these definitions, and the other 2 want to use another control, then what to do?

The definition of a style as a resource is actually in 2 ways.
One is to use the TargetType property of the style directly to define all the target controls.
In addition to using the TargetType property, you can also use the X:key property, and then the specific control of the golden mean explicit keyword StaticResource to set the specific style property.

<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 specific effect, where the opacity property is transparency.

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

"Miles Journey--windows App development" control large collection "patching"

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.