Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set startup uri property to another window in folder in wpf project

In my wpf project i have created a folder called practice, in that folder i added a window, now i want to run that window, so in app.xaml file i set the startup uri to foldername.window.xaml but it is saying build action property is not set to resource.

for that i setted build action property to resource. Now this time that it is showing error message initialized componenet doesn't exist in the current context.

Can you tell me what properties we need to set when we create separate folders in wpf project and that folders contains windows or pages. and How to access those pages in other pages or in App.Xaml file startupUri Property.

like image 802
Sekhar Babu Avatar asked Aug 12 '13 05:08

Sekhar Babu


2 Answers

If the XAML is inside any Folder the startup url will be defined as below.

enter image description here

This is how it will defined. enter image description here

like image 161
Debendra Dash Avatar answered Nov 05 '22 05:11

Debendra Dash


When you have folders in your project structure, you should use a "/" not a ".", so it's foldername/window.xaml.

(I hope it's not actually called window.xaml by the way. That's a confusing name for a type in a WPF project, because there's a built in type called Window.)

Setting the build action to Resource will make matters worse: not only were you using the wrong name, you've now changed the build action to the wrong one for XAML. The correct build action for a .xaml file is usually Page. (App.xaml is an exception to that rule.) The Page build action causes the page to be compiled into a binary representation (known as BAML), and that binary format can then be loaded either by the call to InitializeComponent in the codebehind, or through Application.LoadComponent.

Setting the build action to Resource will just embed a copy of the XAML source directly in the project, which won't help you - you can't work with XAML in that form if you want to have a codebehind file. (Not in WPF, anyway. It's different in other XAML-based frameworks such as WinRT.)

Since Page is the default build action for a newly-added window, you don't actually need to set any properties at all. You just need to use / for folder boundaries.

like image 43
Ian Griffiths Avatar answered Nov 05 '22 04:11

Ian Griffiths