How to set uri launch property to another window in a folder in a wpf project

In my wpf project, I created a folder called practice, in this folder I added a window, now I want to run this window, so in the app.xaml file I set the uri to run in the name.window.xaml folder, but it says the action property action is not defined by the resource.

To do this, I set the action build property for the resource. Now this time, when it shows an error message, the initialized componentenet does not exist in the current context.

Can you tell me what properties we need to set when we create separate folders in the wpf project, and these folders contain windows or pages. and How to access these pages on other pages or in the StartupUri file for App.Xaml.

+4
source share
1 answer

When you have folders in the project structure, you should use "/", not ".", So it is foldername/window.xaml .

(I hope this is not really called window.xaml . This is a confusing name for a type in a WPF project, because there is a built-in type called Window .)

Setting the assembly action on the resource will aggravate the situation: you used the wrong name not only, but now you have changed the assembly action to the wrong one for XAML. The correct build action for the .xaml file .xaml usually Page . ( App.xaml is an exception to this rule.) The Page assembly action forces the page to compile into a binary representation (known as BAML), and this binary format can then be loaded either by calling InitializeComponent in the codeb or through Application.LoadComponent .

Setting the build action in Resource simply inserts a copy of the XAML source directly into the project, which will not help you - you cannot work with XAML in this form if you want to have a codebehind file. (In WPF, anyway, this is not the case with other XAML-based frameworks such as WinRT.)

Since Page is the standard build action for a newly added window, you actually do not need to set any properties at all. You just need to use / for the borders of the folders.

+10
source

Source: https://habr.com/ru/post/1496502/


All Articles