Any additional feedback? Namespace: System. Windows Assembly: PresentationFramework. Encapsulates a Windows Presentation Foundation application. Note A standalone application does not require an Application object; it is possible to implement a custom static entry point method Main that opens a window without creating an instance of Application. In this article. Inherited from DispatcherObject. Gets or sets a collection of application-scope resources, such as styles and brushes.
Gets or sets a UI that is automatically shown when an application starts. Equals Object. Determines whether the specified object is equal to the current object. Inherited from Object. FindResource Object. GetContentStream Uri. GetCookie Uri.
Serves as the default hash function. GetRemoteStream Uri. GetResourceStream Uri. LoadComponent Object, Uri. LoadComponent Uri. OnActivated EventArgs. OnDeactivated EventArgs. OnExit ExitEventArgs. OnNavigated NavigationEventArgs. OnStartup StartupEventArgs. Run Window. Starts a Windows Presentation Foundation application and opens the specified window. SetCookie Uri, String. Shutdown Int This allows the code-behind file to be associated with the partial class that is generated for the markup file when the application is built, for more information, see Compile a WPF Application.
In code-behind, the Window class must implement a constructor that calls the InitializeComponent method. InitializeComponent is implemented by the markup file's generated partial class to register events and set properties that are defined in markup. When you add a new Window to your project by using Visual Studio, the Window is implemented using both markup and code-behind, and includes the necessary configuration to create the association between the markup and code-behind files as described here.
With this configuration in place, you can focus on defining the appearance of the window in XAML markup and implementing its behavior in code-behind. The following example shows a window with a button that defines an event handler for the Click event. This is implemented in the XAML and the handler is implemented in code-behind.
How you implement your window determines how it's configured for MSBuild. For a window that is defined using both XAML markup and code-behind:. To open a window, you first create an instance of it, which is demonstrated in the following example:. In this example Window1 is instantiated when the application starts, which occurs when the Startup event is raised. For more information about the startup window, see How to get or set the main application window.
When a window is instantiated, a reference to it's automatically added to a list of windows that is managed by the Application object.
The first window to be instantiated is automatically set by Application as the main application window. The window is finally opened by calling the Show method as shown in the following image:. A window that is opened by calling Show is a modeless window, and the application doesn't prevent users from interacting with other windows in the application. Opening a window with ShowDialog opens a window as modal and restricts user interaction to the specific window.
For more information, see Dialog Boxes Overview. When Show is called, a window does initialization work before it's shown to establish infrastructure that allows it to receive user input. When the window is initialized, the SourceInitialized event is raised and the window is shown.
For more information, see How to open a window or dialog box. The previous example used the Startup event to run code that displayed the initial application window. The application automatically creates and displays the window specified by that property. A window that is opened by using the Show method doesn't have an implicit relationship with the window that created it.
Users can interact with either window independently of the other, which means that either window can do the following:. Some windows require a relationship with the window that opens them.
For example, an Integrated Development Environment IDE application may open property windows and tool windows whose typical behavior is to cover the window that creates them. Furthermore, such windows should always close, minimize, maximize, and restore in concert with the window that created them. Such a relationship can be established by making one window own another, and is achieved by setting the Owner property of the owned window with a reference to the owner window.
This is shown in the following example. When a window is first opened, it becomes the active window. The active window is the window that is currently capturing user input, such as key strokes and mouse clicks. When a window becomes active, it raises the Activated event. When a window is first opened, the Loaded and ContentRendered events are raised only after the Activated event is raised.
With this in mind, a window can effectively be considered opened when ContentRendered is raised. After a window becomes active, a user can activate another window in the same application, or activate another application. When that happens, the currently active window becomes deactivated and raises the Deactivated event. Likewise, when the user selects a currently deactivated window, the window becomes active again and Activated is raised. One common reason to handle Activated and Deactivated is to enable and disable functionality that can only run when a window is active.
For example, some windows display interactive content that requires constant user input or attention, including games and video players. The following example is a simplified video player that demonstrates how to handle Activated and Deactivated to implement this behavior.
Other types of applications may still run code in the background when a window is deactivated. For example, a mail client may continue polling the mail server while the user is using other applications.
Applications like these often provide different or extra behavior while the main window is deactivated. For a mail program, this may mean both adding the new mail item to the inbox and adding a notification icon to the system tray.
A notification icon need only be displayed when the mail window isn't active, which is determined by inspecting the IsActive property. If a background task completes, a window may want to notify the user more urgently by calling Activate method.
If the user is interacting with another application activated when Activate is called, the window's taskbar button flashes. However, if a user is interacting with the current application, calling Activate will bring the window to the foreground. You can handle application-scope activation using the Application.
Activated and Application. Deactivated events. There are scenarios where windows shouldn't be activated when shown, such as conversation windows of a chat application or notification windows of an email application. If your application has a window that shouldn't be activated when shown, you can set its ShowActivated property to false before calling the Show method for the first time.
As a consequence:. The window will become activated, however, as soon as the user activates it by clicking either the client or non-client area. Provides a base class for elements that apply effects onto or around a single child element, such as Border or Viewbox. Defines the functionality required to support a shared-size group that is used by the ColumnDefinitionCollection and RowDefinitionCollection classes. This is an abstract class.
Defines an area where you can arrange child elements either horizontally or vertically, relative to each other.
Represents a document viewing control that can host paginated FixedDocument content such as an XpsDocument. Represents a rule that checks for exceptions that are thrown during the update of the binding source property.
Represents the control that displays a header that has a collapsible window that displays content. Represents a control for viewing flow content in a fixed viewing mode that shows content one page at a time. Represents the control that redistributes space between columns or rows of a Grid control. Represents a view mode that displays data items in columns for a ListView control. Represents a collection of GridViewColumn objects.
Represents a column header for a GridViewColumn. Represents a control that creates a container that has a border and a header for user interface UI content. Provides data for the InitializingNewItem event. Provides data for the Gesture event. Provides data for the SelectionChanging. Provides data for the SelectionMoving and SelectionResizing events. Provides data for the StrokeCollected event. Provides data for the StrokeErasing event.
Provides data for the StrokesReplaced event. Holds the list of items that constitute the content of an ItemsControl. Generates the user interface UI on behalf of its host, such as an ItemsControl. Provides the template for producing a container for an ItemsControl object.
Provides a resource key for an ItemContainerTemplate object. Specifies the panel that the ItemsPresenter creates for the layout of the items of an ItemsControl.
Used within the template of an item control to specify the place in the control's visual tree where the ItemsPanel defined by the ItemsControl is to be added. Provides data for the KeyTipAccessed event.
Represents a service that provides properties, methods, and events to enable and manage KeyTips in WPF Ribbon controls.
Represents a selectable item in a ListBox. Represents an item in a ListView control. Represents a Windows menu control that enables you to hierarchically organize elements associated with commands and event handlers. Represents a selectable item inside a Menu. Represents a data-binding converter to handle the visibility of repeat buttons in scrolling menus. Represents a rule that checks for errors that are raised by a data source that implements INotifyDataErrorInfo.
Encapsulates a page of content that can be navigated to and hosted by Windows Internet Explorer, NavigationWindow , and Frame. Provides a base class for all Panel elements. Invokes a standard Microsoft Windows print dialog box that configures a PrintTicket and PrintQueue according to user input and then prints a document. The exception that is thrown when an error condition occurs during the opening, accessing, or using of a PrintDialog.
Represents a button that can be selected, but not cleared, by a user. The IsChecked property of a RadioButton can be set by clicking it, but it can only be cleared programmatically. Represents a rich editing control which operates on FlowDocument objects. Defines row-specific properties that apply to Grid elements. Provides access to an ordered, strongly typed collection of RowDefinition objects. Describes a change in the scrolling state and contains the required arguments for a ScrollChanged event.
Displays the content of a ScrollViewer control. Provides data for the SelectedCellsChanged event. Represents a set of selected dates in a Calendar. Provides data for the SelectionChanged event. Represents a control that lets the user select from a range of values by moving a Thumb control along a Track. Represents a lightweight audio playback TriggerAction used to play. Provides real-time spell-checking functionality to text-editing controls, such as TextBox and RichTextBox.
Represents a misspelled word in an editing control i. TextBox or RichTextBox. Represents a selectable item inside a TabControl. Contains information about the changes that occur in the TextChanged event.
Provides data for the TextChanged event. Represents the container that handles the layout of a ToolBar. Represents a control that creates a pop-up window that displays information for an element in the interface. Represents a service that provides properties and events to control the display and behavior of tooltips.
Represents a control that displays hierarchical data in a tree structure that has items that can expand and collapse. Implements a selectable item in a TreeView control. Represents an ordered collection of UIElement child elements. Represents a validation error that is created either by the binding engine when a ValidationRule reports a validation error, or through the MarkInvalid BindingExpressionBase, ValidationError method explicitly.
Provides information for the Error attached event. Represents the result returned by the ValidationRule. Validate Object, CultureInfo method that indicates whether the checked value passed the ValidationRule.
Represents the base class for views that define the appearance of data in a ListView control. Defines a content decorator that can stretch and scale a single child to fill the available space. Renders the contained 3-D content within the 2-D layout bounds of the Viewport3D element. Converts objects to and from a VirtualizationCacheLength.
Provides a framework for Panel elements that virtualize their child data collection.
0コメント