1024programmer Asp.Net WPF Getting Started Notes – 01 – Getting Started Basics and Common Layouts

WPF Getting Started Notes – 01 – Getting Started Basics and Common Layouts

WPF Getting Started Notes – 01 – Getting Started Basics and Common Layouts

WPF Getting Started Notes - 01 - Getting Started Basics and Common Layouts
🥑This article is a note taken for studying the “WPF Basics to Enterprise Application Series” by Templar, the master of the blog garden, and the “WPF Introductory Tutorial Series” from some DotNet vegetable gardens, corresponding to the 1st – of Templar’s “WPF Basics to Enterprise Application Series” The content between 6 chapters includes WPF project structure, program startup and shutdown, program life cycle, inheritance relationship, and common layout controls and their applications. If you have any questions about the article, please feel free to interact in the comment area, thank you!

🥑This article is a note taken for studying the “WPF Basics to Enterprise Application Series” by Templar, the master of the blog garden, and the “WPF Introductory Tutorial Series” from some DotNet vegetable gardens, corresponding to the “WPF Basics to Enterprise Application Series” by Templar The content between Chapters 1 – 6 includes WPF project structure, program startup and shutdown, program life cycle, inheritance relationship, and common layout controls and their applications. First link:

Templar Blog Index

DotNet vegetable garden

WPF core assembly

After creating a WPF, the project references will reference PresentationCore, PresentationFramework, and WindowsBase by defaultWPFCore Assembly:

image-20230516115833980

  1. PresentationCore: Defines the basic UI elements in WPF and the core functions of the presentation system, including layout, rendering, input, events, etc. . It contains many basic classes and interfaces, such as UIElement, Visual, DispatcherObject, Freezable, etc.
  2. PresentationFramework: This is the application framework in WPF, which provides some advanced UI controls and application-level functions, such as Windows, Pages, Navigation, Application, Window, etc. In addition, PresentationFramework also defines the namespace, style and theme of WPF.
  3. WindowsBase: It contains some basic classes and interfaces to support PresentationCore and PresentationFramework, such as DependencyObject, DependencyProperty, RoutedEvent, FrameworkElement, etc.

File structure

The file structure generated by default is as follows:

image-20230516143847692

In App.xaml, you can specify the form to be started when the project is running. The default is the main form: MainWindow. In addition, you can also define the required system Resources and operations such as introducing assemblies – App.xaml:

image-20230519101618613

Design the main form style in MainWindow.xaml: Modify the title to: XAMLWithScript, then add a Button button, and do some Do some simple “initialization” of the button – MainWindow.xaml:

image-20230519103947108

The current XAML style renders a Button with the title XAMLWithScript and a content of OnClick :

image-20230519104204005

The events defined in the style are in the background page MainWindow.xaml.cs of the current page:

image-20230519104350444

WPF and Winform case

  • 6.WPF and WinForm cases

Application

WPF is similar to the traditional WinForm . WPF also requires an Application to control some global behaviors and operation, and only one Application instance can exist in each Domain (application domain). Different from WinForm , WPF Application consists of two parts by default: App.xaml and App.xaml.cs , which is somewhat similar to Delphi Form (I only understand this and have not been exposed to Delphi), which separates definition and behavior code. Of course, this and

Border border = new Border();
 border.Width = 270;
 border.Height = 250;
 border.HorizontalAlignment = HorizontalAlignment.Center;
 border.VerticalAlignment = VerticalAlignment.Center;
 border.Background = Brushes.LightGray;
 border.BorderBrush = Brushes.LightGreen;
 border.BorderThickness = new Thickness(8);
 border.CornerRadius = new CornerRadius(5);

 Canvas canvas = new Canvas();
 canvas.Background = Brushes.LightYellow;

 Rectangle rectangle = new Rectangle();
 rectangle.Width = 150;
 rectangle.Height = 150;
 rectangle.Fill = Brushes.Red;
 rectangle.Stroke = Brushes.Black;
 rectangle.StrokeThickness = 10;
 Canvas.SetLeft(rectangle, 30);
 Canvas.SetTop(rectangle, 20);

 canvas.Children.Add(rectangle);
 border.Child = canvas;

 //Add the Border to the main Window
 this.Content = border;
 

ScrollViewer

ScrollViewer is a commonly used scrolling container control in WPF, used to provide scrolling functionality when needed to display content beyond the visible area of ​​the container. It can contain a single child element and display scroll bars vertically and/or horizontally as needed.

The following are some common properties of the ScrollViewer control:

  1. HorizontalScrollBarVisibility (horizontal scroll bar visibility): Specifies the visibility of the horizontal scroll bar. Common values ​​include:
    • Disabled: Disables the horizontal scroll bar.
    • Auto: Automatically displays horizontal scroll bars as needed.
    • Visible (visible): Always display horizontal scroll bars.
  2. VerticalScrollBarVisibility (vertical scroll bar visibility): Specifies the visibility of the vertical scroll bar. Common values ​​include:
    • Disabled: Disables the vertical scroll bar.
    • Auto: Automatically displays vertical scroll bars as needed.
    • Visible (visible): Always display vertical scroll bars.
  3. CanContentScroll (Content Scroll): Specifies whether the ScrollViewer scrolls content in logical units (such as rows or items). When set to True, the scrollbar will scroll in logical units instead of pixels.
  4. Content (content): Specifies a single child element of ScrollViewer. This child element will be contained in the scroll container and can be scrolled as needed.

By using the ScrollViewer control, you can place content in a scrollable container, display the content outside the visible area of ​​the container, and navigate through the content with scroll bars. This is useful when dealing with large amounts of content or where large elements need to be displayed to keep the interface usable and accessible.

image-20230520145935943


     
         
             
         
     
 
 

🔊Only one child element can be placed

Layout Comprehensive Application

Syria Battle Damaged Version Microsoft ToDo Layout – Not Recommended

image-20230520155138778


     
         
             
             
         
         
             
             
             
             
             
             
             
             
         
         
             
             
             
             
                 
             
         
         
         
         
     
 

 

If you really see this, then I think this thing is really – Thai pants are hot! ! ! 🤔

Custom Panel

This chapter has been omitted and has not been read. . .

om/blog/2913706/202305/2913706-20230520155139308-1559934408.png” alt=”image-20230520155138778″ loading=”lazy”>


     
         
             
             
         
         
             
             
             
             
             
             
             
             
         
         
             
             
             
             
                 
             
         
         
         
         
     
 

 

If you really see this, then I think this thing is really – Thai pants are hot! ! ! 🤔

Custom Panel

This chapter has been omitted and has not been read. . .

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/wpf-getting-started-notes-01-getting-started-basics-and-common-layouts/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索