Steps to add a xaml file and its associated xaml.cs into a VS2010 project
Asked Answered
E

5

7

I am new to MVVM therefore I understand this is a beginner question but I have not found the answer so far.

But in the View project of a MVVM style, what are the steps to add a XAML file to the project. When the project is selected in the solutions Explorer and Add ->Item is selected then how do you make sure that a XAML file is added. or there is no magical way to do it and you just add a .CS file and then change the extention to XAML.

Thanks for any help or references to any URLs.

Extortionary answered 16/7, 2013 at 15:1 Comment(0)
K
13

Just right click the project, choose Add -> Window and that will add a new xaml file along with its corresponding .cs file.

Kwiatkowski answered 16/7, 2013 at 15:16 Comment(4)
There is Add but no Window , there is Windows Form but when I add that there is no xaml file and its associated .cs file. This is vs2010, are you in the same environment. At any rate if you could elaborate more maybe I could follow it better. Thank you.Extortionary
@Extortionary - I am using VS 2010. Is your project a WPF project? What happens if you choose Add -> New Item and then from the dialog that appears, click on the WPF category.Kwiatkowski
@"Chris Dunaway" That works thank you. It is a WPF project within a Winform, maybe that was also one reason for my confusionExtortionary
Didn't yet answer my problem I'm having where a .xaml already exists. I guess I'll just create a new one.Xhosa
M
0

When I want to create a style file to be used on more than one Window I Add a "WPF/Resource Dictionary" and add it to the Window.Resources of the windows that will use it. Something like this below. Everything you want to put within the Window.Resources should be placed between the ResourceDictionary tags.

<Window.Resources>
 <ResourceDictionary>
  <ResourceDictionary Source="scrollerDictionary.xaml"/>
 </ResourceDictionary>
</Window.Resources>
Monson answered 18/8, 2016 at 17:20 Comment(0)
R
0

For me selecting the .xaml file is VS2022 solution explorer, viewing Properties, then changing the Build Action from "None" to "Page" resolved the issue.

Rosarosabel answered 12/8, 2022 at 14:45 Comment(0)
D
-1

This works for me, copy the template into the folder for the user:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Xamarin\Xamarin\4.0.3.214\T\IT\Cross-Platform\Code

to

C:\Users\your name here\Documents\Visual Studio 2015\Templates\ItemTemplates\Visual C#

Original answer: http://damianblog.com/2016/04/08/vs2015-xaml-forms-xaml-missing/

Denny answered 22/11, 2016 at 11:29 Comment(1)
A link to a potential solution is always welcome, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Take into account that being barely more than a link to an external site is a possible reason as to Why and how are some answers deleted?.Countersubject
S
-1

This works for me (VS 2022) Right-click project or use Project menu then click

  • Add -New Item (or Add New Item) Choose the "Blank Page" and enter the name of the Window you will be adding, eg name.xaml Then Click Add (bottom right). Both the .xaml and the associated .cs should appear
Stand answered 9/6, 2022 at 8:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.