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:
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.
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.
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:
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:
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:
The current XAML style renders a Button with the title XAMLWithScript and a content of OnClick :
The events defined in the style are in the background page MainWindow.xaml.cs of the current page:
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:
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.
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.
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.
🔊Only one child element can be placed
Layout Comprehensive Application
Syria Battle Damaged Version Microsoft ToDo Layout – Not Recommended
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. . .