Creating Pages or Windows in WPF

前端 未结 4 1753
别那么骄傲
别那么骄傲 2021-02-20 13:46

I\'m new to using WPF. I have the following program I want to create: -Application opens up with one button -User clicks button and it takes them to a new page with various inpu

4条回答
  •  心在旅途
    2021-02-20 14:23

    Initially there doesn't seem to be much of a difference in the preference of what should be used: Pages or Windows. However, looking at the intended goal of the application, I would suggest using UserControls instead of Pages, as Pages seem to focus on Web related content, though they can be used in stand alone applications as well. Another argument that has been made in another post is referring to the MSDN-documentation, and points out that in using a Page the NavigationWindow that it is hosted in does not remember the instance of the content that is navigated to and thus other WPF-techniques are needed to store that content in your navigation history.

    NavigationWindow does not store an instance of a content object in navigation history. Instead, NavigationWindow creates a new instance of the content object each time it is navigated to by using navigation history. This behavior is designed to avoid excessive memory consumption when large numbers and large pieces of content are being navigated to. Consequently, the state of the content is not remembered from one navigation to the next. However, WPF provides several techniques by which you can store a piece of state for a piece of content in navigation history.

    If you use a UserControl, you wouldn't have that problem if your goal is to create a native application anyway. You can download this template as an example to use UserControls instead.

提交回复
热议问题