How to change ComboBox Dropdown Background? - xaml

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>

Related

How can I use other icons as the ones in the SymbolIcon enumeration?

I use SymbolIcon controls in my UWP app, which is very handy. But I see other apps use more symbols than are provided by the enumeration. How can I use them as well?
The SymbolIcon enumeration is a standard set of common icons. But they are actually shortcuts to characters in the Segoe MDL2 Assets font. If you open up Word you can select that font. If you then go to Insert - Symbols - Symbol - More Symbols … you see all the icons available in that font. If you click on one of those icons, you see also the character code of that icon (e.g. the Headset icon is E95B).
To use those others, you can use the FontIcon control and set the Glyph property. There are different ways to set it, depending on where you use it. For the example Headset icon with character code E95B you would do it this way:
In XAML you can define it like this:
<FontIcon x:Name="SampleFontIcon" Glyph="" FontSize="200" />
You need to preceed the value by &#x and close it with a semicolumn. And as you see you can determine the size with the FontSize attribute.
If you want to set the value in C# code, you do it like this:
SampleFontIcon.Glyph = "\uE95B";
I once wanted to debug the values and came up with this method to show the value:
private string getUnicodeString(string input)
{
    byte[] bytes = Encoding.Unicode.GetBytes(input);
    if (bytes.Length == 0) return "";
    string output = "\\u";
    for (int i = bytes.Length - 1; i >= 0; i--)
        output += string.Format("{0:X}", bytes[i]);
    return output;
}
Now you can convert a glyph value back to something you're familiar with in code.
Martin's answer is absolutely right, just two points from me.
If you want to see all possible Segoe icons, better than Word is just run built-in Windows app 'Character Map', where you select 'Segoe MDL2 Assets' and you see codes and icons.
You can also use this icons even in basic TextBlock, you just have to change FontFamily:
<TextBlock FontFamily="Segoe MDL2 Assets"
Text=""
..... />

How can I make the background of an checkbox transparent in wix?

How can I make the background of the checkbox transparent or white?
That is quite common complaint. The quick answer is - no, there's no way to do it nicely. Let me quote the WiX Toolset tutorial:
And a common complaint: no, the checkbox can't have a transparent
background. If you have a bitmap in the background, it will be ugly,
just like in our example above. The only workaround is to reduce the
width of the checkbox to the actual box itself and to place an
additional static text (these can be made transparent) adjacent to it.
The downside of the workaround described is you won't be able to click the text in the label to check/uncheck the checkbox. You'll have to click directly into the control.
There is, however, one more (even uglier?) workaround: design the final dialog the way to have default grey area to place the checkbox on.
A workaround I have used is to create a new version of the built-in WiX dialog set "Mondo" where I modify the end dialog to contain a much smaller picture which does not cover the whole dialog surface. This should allow the natural background color - normally gray - to fill the rest of the dialog. Screenshot below:
https://github.com/glytzhkof/WiXOpenLogFile
There could be side-effects, but this should allow the dialog's background color to fill the dialog properly:
Main wxs file snippet:
<Binary Id="MyOwnExitBitmap" SourceFile="myOwnExit.bmp" />
Dialog wxs file snippet:
<Control Id="Bitmap" Type="Bitmap" X="0" Y="0" Width="70" Height="70" TabSkip="no" Text="MyOwnExitBitmap" />
See full example above on github.com.
Not a direct answer but just another workaround that can be ok in some cases. If that's just one checkbox like launch app/readme/whatever - then it can be placed to the buttons panel which has the same background:

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

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.

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