Is there a way to automatically reformat Blend's XAML view? - xaml

Blend tends to create its XAML in very long lines.
Is there a way to reformat it so that the properties of each element are lined up vertically under each other?

There isn't a feature in Blend that will autoformat XAML. I usually do xaml formatting with Visual Studio.
Another option is to paste your XAML into Kaxaml and use its excellent XAML scrubber, then paste the result back into Blend.
You can see a demo on Channel9: http://channel9.msdn.com/shows/Continuum/Kaxaml/

You can do it by using Visual Studio:
Change the default settings for XAML documents, and then use CTRL+E,D (Edit | Advanced | Format Document) or CTRL+E,F (Edit | Advanced | Format Selection).
http://weblogs.asp.net/fmarguerie/archive/2008/06/07/xaml-markup-formatting-in-visual-studio.aspx

Or try xaml styler hosted at http://xamlstyler.codeplex.com/ for visual studio 2010. If you ever used Kaxaml's Xaml Scrubber and you like it, then you could think of this extension is the "Xaml Scrubber" for Visual Studio.
Check http://xamlstyler.codeplex.com/ for feature highlights.

Go into Visual Studio. (I'm using 2012).
Tools > Options > Xaml Styler (at the bottom)
Under Misc
Set Beautify on saving xaml to FALSE
You can now save your xaml however you like, and it will stay like that.

Related

VS 2022 Preview not showing the XAML designer

I've just installed VS 2022 preview to use Maui but there seems no way to see a designer view of the XAML, I want to drag and drop controls onto the page but all I get is an ancient looking XAML text view.
Visual Studio has removed the XAML designer. For now, there is no official plan to readd it.
But Visual Studio support Hot Reload to modify your apps managed source code while the application is running, without the need to manually pause or hit a breakpoint. You could preview the view at runtime when you change the UI. For more details, please check the blog. https://devblogs.microsoft.com/dotnet/introducing-net-hot-reload/
Like Cfun said, you could use live visual tree as well. It shows a tree view of the UI elements of your running Xamarin.Forms application. https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/live-visual-tree
For a WPF dotnet6 project, the XAML designer can be enabled here:
Don't know why it's disabled by default.

Cannot get Xamarin Xaml Intellisense working in VS 2015

I've been trying to get intellisense working for quite some time now, and am unable to see anything outside of
!
![CDATA[
?
Visual Studio 2015 Update 2
Resharper is installed but disabled
Referencing the latest pre-releases of Xamarin Forms (2.3.0.38-pre2)
Xamarin for Visual Studio (4.2.21)
Portable project referencing the proper 2.3.0.38-pre2 targets file from NuGet
Enable XAML Language for Xamarin.Forms
What else am I missing? I feel like it shouldn't be this difficult.
I resolved this issue by doing a simple workaround and here is the solution.
Right-click the XAML file in the Solution Explorer and select
Solution 1: "Open With... > Source Code (Text) Editor".
and in another time this also worked for me:
Solution 2: "Open With... > Source Code (Text) Editor with Encoding"
This workaround gave me the desired XAML IntelliSense even without installing the extra "Enable XAML Language for Xamarin.Forms" extension and even with ReSharper installed but suspended.
Extensions > Tools > Enable XAML Language for Xamarin.Forms
Enable XAML Language for Xamarin.Forms
Enables the VS built-in XAML language service to provide editing and intellisense for Xamarin.Forms XAML files.
https://visualstudiogallery.msdn.microsoft.com/8195a8e2-a842-4389-a8cb-34e4672e2e13
Update:
From #Jeff:
Seems I had to completely uninstall Resharper, not just disable it. Then reinstall the "Enable XAML Language for Xamarin Forms extension".
Additional info:
http://www.cazzulino.com/enable-xaml-forms-intellisense.html
Xamarin XAML Enabled:
XML Enabled and thus no Xamarin XAML Intellisense:
The reason why Intellisense is not appear in editor is that Xamarin XAML is not opened as file with content type xaml but file with content type xml.
To open xamarin XAML file as file with content type xaml simply in solution explorer right click the xaml file and select Open With... In popup select "XAML Designer with Encoding" and click OK.
Solution below is if you edit Xamarin xaml as file with content type xml. But this solution is not correct, IntelliSense then not always correctly suggests.
To take advantage of Intellisense the Visual Studio must get appropriate definition of xml namespace for Xamarin.Forms. For the Xamarin.Forms Visual Studio needs xml definition for namespace http://xamarin.com/schemas/2014/forms.
This definition can be provided to Visual Studio by two ways:
You can use xsd file and this file then register to xml schemas - after you open xaml file, the menu Xml/Schemas appear.
You can this definition create by assembly attribute XmlnsDefinitionAttribute. This attribute you can found in Portable.Xaml nuget package.
Suitable for Xamarin.Forms is the second way(using attribute).
If you use Xaml in portable library, restore(download and install) this nuget package to this library.
If you use shared project, then restore this nuget package to all projects referencing this shared project.
Then insert this attribute to appropriate place. I believe that the App.xaml.cs(if you use generated name App) is a good place. The code could look like this:
using Portable.Xaml.Markup;
using Xamarin.Forms;
[assembly: XmlnsDefinition("http://xamarin.com/schemas/2014/forms", "Xamarin.Forms")]
namespace YourAppNamespace
{
public partial class App : Application
{
public App ()
{
this.MainPage = new MainPage();
}
}
}
And the rebuild solution, as I believe, might not be necessary to work Intellisense for Xamarin.Forms.
This worked for me:
right click on .xaml file and then select "Open With.." and select "XAML Designer" and also "Set as Default" then intellisense worked great.
I install the Extension Enable XAML Language for Xamarin.Forms from
Enable XAML Language for Xamarin.Forms
Still the intellisense was not working. I just need to close all tabs and close the visual studio. After re-starting Visual studio I open solution and XAML file. The instellisense is working fine.
worked for me
Right click on Your XAML file and choose Option
Open With=>Source Code(Text) Editor with Encoding=>Set as default=>Apply and choose option Auto....
Seems I had to completely uninstall Resharper, not just disable it. Then reinstall the Enable XAML Language for Xamarin Forms extension.
Jeff's answer almost worked for me, but I had to do one additional step:
Because I had previously uninstalled and reinstalled Xamarin, I had to update from 4.0.1 to the latest stable (4.1.1.3 as of this date). After that Intellisense started working!
I have Resharper installed on VS2015update3, and XAML Designer didn't work for me.
But accidently I found XML (Text) Editor works. That's Resharper that makes effet.
No wave-line beneath the tag
Perfect prompt everywhere: XML Tags, Properties, available Values
Only things: it doesn't color too much, and F7 do not send me to its code-behind.
VoilĂ , hope this could help
I resolved this issue by doing a simple workaround and here is the
solution.
Right-click the XAML file in the Solution Explorer and select
Solution 1: "Open With... > Source Code (Text) Editor".
and in another time this also worked for me:
Solution 2: "Open With... > Source Code (Text) Editor with Encoding"
Actually, I found that for me it even worked by simply choose:
Solution 2: "Open With... > Automatic Editor Selector (XML)" and then reopening VS.
I also found that the problem began after editing .xaml file outside of VS, by right-clicking the file and choose "Edit".

Visual Studio 2012 XAML Designer Vertical Split Can't Be Set As Default?

Is there only Horizontal Split as default and not Vertical Split? Again or my eyes are going bad? It was an issue in VS2008 and VS2010 when it was per-file basis so nothing has changed?
Yep there is currently no way of defaulting to a vertical split for the XAML designer in VS2012.
Like you mentioned the only way at this point is doing it per-file basis as these settings are saved together in your .suo file.
This applies to VS08 and VS10 or VS12...
If you do want to let microsoft know that you would like this to be a feature you can send them a request here
Here is the original thread about this issue.
Its funny though that their HTML designer does allow defaulting to vertical split..

View Designer Code in Visual Studio 2010

What is a standard way to open the Designer (automatically generated) code for a VB file?
As a workaround, I can get to it by searching the entire solution for some keyword that is usually only found in those files: Global, Partial, etc.
Open the Solution Explorer. Along the toolbar at the top there is a tool Show All Files (it is the 2nd from the left on my version of visual studio). Click on that tool. All of your Form files will now have an arrow beside them. click on that arrow to expand. Look for the code file named FormName.designer.vb. Double-click on it to open.
You have to click the "show all files"-Button. Then you can also see the Designer.vb-files.
Note: For C# and VS 2008, but the same applies to VB in VS 2010.
http://peterkellner.net/2007/12/31/visualstudioshowallfiles/
http://blog.brianhartsock.com/2009/09/14/visual-studio-tip-show-all-file/
Keyboard shortcut for Show All Files
Show All Files is a useful little button in the Visual Studio solution explorer to give us a full view of the directory structure our project files are sitting in. When it is off, we only see the files that are explicitly included in the project, but when it is on, we see everything. This makes it very easy to explicitly opt a file into the project without doing an add -> existing item -> find existing item in directory structure and add to project.
The default when creating a new Visual Basic application in Visual Studio is to not show all files, and unfortunatly there is no setting you can adjust to change that.
Open the code file, and in the top-right corner of the code window is a drop-down containing all methods. Open this and select "InitializeComponent".
A screenshot from a newer version. Visual Studio 2015 and 2017 will look like this.

How to set default XAML view in Visual Studio 2008

In Visual Studio 2008, when you add a new XAML window to a WPF Application Project, the default view you get is "split view" where the visual designer and the XAML code are shown one above the other in the same document.
I prefer an alternative view which you can get by double-clicking on either the Design or XAML tabs. The visual designer and the XAML are in separate side-by-side tabbed views. This makes it easy to switch between them
I want to know if it possible to make this the default view for all new XAML documents I add to my project, and where in the options you would set it.
Tools/Options/Text Editor/Xaml/Miscellaneous, check the "Always open documents in full XAML view"