How to format xaml properties' indentations in visual studio 2013? - xaml

How can I force Visual Studio 2013 to indent following code?
<Grid>
<TextBlock Margin="42"
Text="yolo"
FontSize="42">
</TextBlock>
</Grid>
Unfortunatelly
CONTROL+K CONTROL+D
and
CONTROL+K CONTROL+F
don't work...
I know that I can rewrite it to
<Grid>
<TextBlock>
<TextBlock.Margin>42</TextBlock.Margin>
<TextBlock.FontSize>42</TextBlock.FontSize>
yolo
</TextBlock>
</Grid>
but i don't want to do this this way.
Update
I can't install Xaml Styler according to #Mashton's answer, because I've got following error.

The only way I know would be to use an extension, such as Xaml Styler, which will break a Xaml onto new lines for each attribute. Other plugins exist, I'm sure, which will give you more control.

Related

How to change ComboBox Dropdown Background?

I have a ComboBox in a UWP project that I want to modify. I want to change the background color of the StackPanel(?) containing the ComboBoxItems, but I haven't found a simple way of doing this.
Here, I want to change the color of the light gray padding.
The color surrounding the ComboBoxItems should match, but instead it is the default gray that stands out.
Here's an example where MSN Money's ComboBox has a custom padding color to match the ComboBoxItems. This is what I am hoping to achieve.
I use the word "padding", but it is really just the color of the element containing the ComboBoxItems.
As I understand it, I have to modify the provided generics.xaml file in the Windows 10 SDK, but that will modify all of the ComboBoxes I'm using. I could create a custom control that inherits from ComboBox, but wouldn't that require me to write a new control whenever I wanted to change this color? There has to be an easier way to change this.
#Bart This is the code I found in the template for the Popup in the ComboBox. I am not sure where "SystemControlBackgroundChromeMediumLowBrush" came from in your explanation.
<Popup x:Name="Popup">
<Border x:Name="PopupBorder"
Background="{ThemeResource ComboBoxDropDownBackground}"
BorderBrush="{ThemeResource ComboBoxDropDownBorderBrush}"
BorderThickness="{ThemeResource ComboBoxDropdownBorderThickness}"
You should NEVER touch the generics.xaml file in the SDK folder, that's a "system file". That's like changing some file deep in your Windows installation to change an icon explorer (and might result in other applications to change this as well).
There are multiple solutions:
Edit the control's template in your own app (with Visual Studio, Blend or by simply copying the default template. If you let it unnamed (name a template by setting x:Key) it will be applied to all your ComboBoxes. If you only want some changed, you should give it a key and use it as StaticResource.
The piece of code you are looking for is the Popup control in the template.
<Popup x:Name="Popup">
<Border
x:Name="PopupBorder"
Background="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}"
BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
BorderThickness="{ThemeResource ComboBoxDropdownBorderThickness}"
Margin="0,-1,0,-1"
HorizontalAlignment="Stretch">
Override the ThemeResource to give it another color. Note that this will have an effect on other controls in your app using the same ThemeResource. But this is still a lot better than changing the generics.xaml and less work than redefining the template.
This is done by redefining the resource key.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="SystemControlBackgroundChromeMediumLowBrush" Color="DarkGray" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>

WP 8.1 XAML: Value Does Not Fall Within The Expected Range

I've run across an annoying error in my Windows Phone 8.1 Runtime app. The error occurs where I defined my CommandBar on my page. That bar has been there almost since the creation of the app, but now the designer decided to make it an error. It reports the error as "Value does not fall within the expected range". Here is the code:
<Page.BottomAppBar>
<!-- ERROR STARTS HERE --><CommandBar x:Name="ButtonBar" Background="{StaticResource StrikeDistanceThemeBrush}" Foreground="{StaticResource StrikeDistanceForegroundBrush}" BorderBrush="White">
<CommandBar.SecondaryCommands>
<AppBarButton x:Name="SettingsButton" Label="settings" Click="SettingsButton_Click"/>
<AppBarButton x:Name="AboutButton" Label="about" Click="AboutButton_Click"/>
<AppBarButton x:Name="AppsButton" Label="more apps"/>
<AppBarButton x:Name="RateButton" Label="rate+review"/>
</CommandBar.SecondaryCommands>
<AppBarButton x:Name="CalculateButton" Label="calculate" Click="CalculateButton_Click" Icon="Calculator"/>
<AppBarButton x:Name="ClearAllButton" Icon="Clear" Label="clear all" Click="ClearAllButton_Click"/>
<AppBarButton x:Name="HelpButton" Icon="Help" Label="help"/>
</CommandBar><!-- ERROR ENDS HERE -->
</Page.BottomAppBar>
Also, the CommandBar does appear while debugging the app, except elements that typically get nudged up (such as my AdDuplex control) don't get moved. So far, these things haven't resolved the problem:
Visual Studio restart
Computer restart
Creating a new CommandBar
Thanks for your help!
Dunno if this will help you or if you've already tried, but you can delete the Visual Studio shadow cache. I use this trick whenever I've tried everything else with no success.
The shadow cache is located here:
%LOCALAPPDATA%\Microsoft\VisualStudio\12.0[this number will change depending on your Visual Studio version]\Designer\ShadowCache
Close Visual Studio, delete everything from this folder then restart Visual Studio. I created a handy little batch file that I can execute to save time.
Hope this helps.

How do I control the AutomationProperties.Name of a Button, such that the value does not use multiple lines?

Suppose I have this XAML in a WinRT app:
<Button Content="" AutomationProperties.Name="Add A New Thing" Style="{StaticResource AppBarButtonStyle}" />
Because the value of AutomationProperties.Name is so long, the text on the button spans two lines. I would like it to stay on a single line. I tried expanding the width of the button to something that would definitely be wide enough for the text, but the text seemed to want to continue to be on two lines. What is the markup I should add to this Button control to keep the text on a single line?
Thanks,
Mike
So, this stumped me. Here's what I tried:
<StackPanel>
<!-- Standard -->
<AppBarButton Label="The quick brown fox jumps over the lazy dog"></AppBarButton>
<!--   -->
<AppBarButton Label="The quick brown fox jumps over the lazy dog"></AppBarButton>
<!-- Underscore -->
<AppBarButton Label="The_quick_brown_fox_jumps_over_the_lazy_dog"></AppBarButton>
</StackPanel>
Each attempt resulted in the exact same result, text wrapping.
This leaves you with two options.
Stop using such long strings
Update the template
So, since you will want to be using an AppBarButton instead of a standard Button with an AppBar style, I'll cater my answer to Windows 8.1 and Visual Studio 2013. I don't have 2012 anyway.
The template (just right click the control in the designer and select Edit Template / Copy. You will find this line, near the bottom:
<TextBlock x:Name="TextLabel"
Foreground="{ThemeResource AppBarItemForegroundThemeBrush}"
FontSize="12" FontFamily="{TemplateBinding FontFamily}" TextAlignment="Center"
TextWrapping="Wrap" Text="{TemplateBinding Label}" Width="88"/>
You can see it is set to wrap. Just change TextWrapping="Wrap" to TextWrapping="NoWrap" and you'll get what you want. Then just make sure all your buttons use the template you have edited (so you might want to relocate it up to app.xaml).
It's that easy, really.
PS: you might be tempted to use a WPF trick of TextBlock.TextWrapping="NoWrap" on the primary control. This does not work, so I can save you time trying.
Best of luck!

Silverlight 4 user control not appearing

I'm new to SL and must be missing something really fundamental here.
I have created a very simple user control like so:-
<UserControl x:Class="Company.UI.Common.Controls.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="Yellow" Width="100" Height="20">
<TextBlock Text="foo"></TextBlock>
</Grid>
</UserControl>
Then in my view I'm referencing it as follows:-
xmlns:medControls="clr-namespace:Company.UI.Common.Controls;assembly=Company.UI.Common"
Then including it in the UI like this:-
<medControls:TestControl Width="100" Height="20" Visibility="Visible" />
However nothing appears when I run the app, just an empty space 100x20 pixels where the control should be. I've used Silverlight Spy and it shows the control being present, with all the correct details - type, assembly, visibility, etc.
I have put a breakpoint in the user control's constructor, and can confirm that InitializeComponent() is being called.
Any suggestions as to what is happening would be greatly appreciated, as I'm tearing my hair out over what should be a very simple thing to do!
Thanks in advance
Andy
This turned out to be a known bug in VS2010, reported here: http://connect.microsoft.com/VisualStudio/feedback/details/683175/visual-studio-failing-to-embed-g-resources-file-in-dll-with-certain-silverlight-project-files
Basically, in some situations, the order of elements in the .csproj file can change, resulting in the XAML files not being included in the assembly, and this is what was happening with me. No runtime errors. Nothing. Just an empty space where the user control should have rendered.
The above link tells you what you need to do to resolve the problem, and involves manually editing the .csproj file and moving certain elements around.
Incidentally, this same bug was also the cause of another problem I'd been having where my user control's code-behind was referencing a control (e.g. "this.txtForename"). The control reference, which is set up in InitializeComponent using FindName(), was always null.
Hope this helps someone else.
Andrew
See if this helps:
http://msdn.microsoft.com/en-us/library/system.windows.controls.usercontrol%28v=vs.95%29.aspx
http://10rem.net/blog/2010/02/05/creating-customized-usercontrols-deriving-from-contentcontrol-in-wpf-4
I never tried to create a custom usercontrol in xaml i always did it programatically, has you can see in this examples, but you can pull it off if you use one ContentControl or one ContentPresenter and then call you UserControl

Latest Silverlight 4 SDK- missing properties?

I have what I believe to be the latest SL4 SDK and tools for Visual Studio 2010. However, I seem to be missing certain properties that I would expect to be seeing.
As an example, when editing a XAML textblock control, I am not seeing the TargetNullValue, StringFormat and FallBackValue properties. I have added a reference to the System.Windows.Data but still nothing shows in the XAML editor.
Can anyone confirm whether I should be seeing these properties or is there something else I should be doing to make these properties visible?
Thanks
They show up for me.
Make sure you are setting up a proper binding:
<TextBlock x:Name="testing" Text="{Binding TargetNullValue=Value}" />