Article 2000 what you should know about the basics of WPF small pose & lt; 40-44 startup shutdown, Xaml, logic tree & gt;

Source: Internet
Author: User

Before starting the text, we need to introduce Sean Sexton. Software Engineer from Minnesota dual city. He maintains two blogs: 2,000 Things You shoshould Know About C # And 2,000 Things You shoshould Know About WPF. He updates an important and easy-to-Forget knowledge of WPF and C # Every day in a 150-word short language similar to Weibo. Follow's blog has been around for a while and I hope to share it with you.

In this series, I will not only translate every tip, but also add my own opinions and opinions in development. In this series, I hope that I can stick to it as well, and every day's progress can make great achievements.

This series is based on mr. Sean Sexton's english blog. Sean Sexton has all rights to copyright and Revoke rights.

 

Previous Article: <1-7>, <8-14>, <15-21>, <22-27>, <28-33>, <34-39>

 

  [Xiao JIU's school is dedicated to describing extraordinary technologies in ordinary languages. If you want to reprint it, please indicate the source: xiaojiu's school. Cnblogs.com/xfuture]

 #40 main WPF Application Forms

A WPF application will create at least one main form, but there is always only one main form MainWindow. The Application. MainWindow attribute specifies the reference of the main form. By default, the primary form is the first created form. Of course, you can manually specify the main form in Xaml.

    

<Application     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    StartupUri="StartupWindow.xaml"    >  <Application.MainWindow>    <NavigationWindow Source="MainPage.xaml" Visibility="Visible"></NavigationWindow>  </Application.MainWindow></Application>

The following example demonstrates how to instantiate the MainWindow

  

public partial class App : Application{    void App_Startup(object sender, StartupEventArgs e)    {        MainWindow window = new MainWindow();        window.Show();    }}

  

#41 ShutdownMode

The WPF Application class contains a ShutDownMode attribute.

  

/// <Summary> /// specify how the application will be closed. Used by the <see cref = "P: System. Windows. Application. ShutdownMode"/> attribute. /// </Summary> public enum ShutdownMode: byte {OnLastWindowClose, OnMainWindowClose, OnExplicitShutdown ,}

Specifies the rules for application shutdown. Generally, it is OnLastWindowClose, that is, when all windows are closed, the application is closed. You can manually specify it as OnMainWindowClose (that is, when the main form is closed, the program is closed) and OnExplicitShutdown (the ShutDown method must be explicitly called, otherwise the program will run in the background even if the window is closed)

  

#42 design three positions of visual elements

  

When designing a graphic element in WPF, The bitlike element can be changed in Window, Page, or UserControl:

Layout)

1. Make changes in the design view in the WPF designer.

2. Directly Change The XAML interface in the WPF Designer.

Change behavior (xaml. cs)

3. Change the C # code in the IDE.

  

 #43 create a Xaml in Visual Studio

Double-click the Xaml code in Visual Studio to open the Xaml code and Design interface of a split screen, as shown below:

  

In the Design Tab, you can drag the control to perform the uidesign. Modify the control in the property bar.

  

In the Xaml Tab, you can directly complete the preceding two steps by modifying the code.

VS will maintain the synchronization between the design interface and the Xaml interface. When one of the modifications is made, the other tab will be updated in real time.

  

  #44 logic tree

The WPF logic tree is a tree of hierarchical relationships of user interface elements. If your UI is defined in Xaml, the logical tree is a model where elements in Xaml are integrated into a tree with parent-child relationships. It describes the relationship between these elements at runtime. The logic tree helps us understand:

1. Resource lookup Resource search

2. Property inheritance

3. Event routing Event.

The following is an example:

  

<Window x:Class="WpfApplication4.MainWindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="A window.." Height="350" Width="525">    <StackPanel>        <Button Content="Click Me" Height="23" HorizontalAlignment="Left" Width="75" Click="button1_Click" />        <TextBox />        <ListBox>            <ListBoxItem Content="Barley"/>            <ListBoxItem Content="Oats"/>        </ListBox>    </StackPanel></Window>

The logic tree model is:

  

  

 

 

Later, we will continue to explore the WPF internal mechanism. Stay tuned!

Recommendation: his girlfriend's "Webpage Design" Path

If it is helpful, click here in the lower right corner ~ (**)

 

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.