Search

Selected ListBoxItem does not have a background of ControlBrushkey when app is unfocused by mabster

Closed
as By Design Help for as By Design

5
0
Sign in
to vote
Type: Bug
ID: 750655
Opened: 6/24/2012 3:09:44 PM
Access Restriction: Public
0
Workaround(s)
3
User(s) can reproduce this bug
In .NET 4 (even using VS2012 when targeting .NET 4), a ListBoxItem is rendered with a background of SystemColors.ControlBrush when it is selected but the app loses focus.

In .NET 4.5, selected ListBoxItems are rendered with a colour that looks like SystemColors.ControlBrush, but seems to be hard coded.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012 RC

Steps to reproduce

MainWindow.xaml

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListBox x:Name="foo">
            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Orange" />
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Lime" />
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
            </ListBox.Resources>
        </ListBox>
    </Grid>
</Window>

MainWindow.xaml.cs

// add to ctor
foo.ItemsSource = new[]
             {
                "The quick",
                "Brown fox",
                "Jumps over",
                "The lazy dog",
            };

Run the app, select an item and then switch away from the app. The selected item will be light grey.

Now retarget the app to .NET 4.0 rather than .NET 4.5. The same app will render the selected item in green when you switch away from the app.

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

The selected item is light grey when the app loses focus.

Expected results

The selected item should be lime green when the app loses focus.
File Attachments
0 attachments
Sign in to post a comment.
Posted by StormENT on 8/29/2012 at 3:25 AM
FrameworkCompatibilityPreferences.AreInactiveSelectionHighlightBrushKeysSupported is only supported in 4.5 but I get the highlight colours targeting 4 running on win 8. Is there a way to turn off this behaviour when targeting 4?
Posted by elyohma on 8/24/2012 at 4:45 AM
This change should have been documented under the breaking changes between .Net 4 and .Net 4.5. One of WPF's core design principles is that you can restyle all the controls. What is the point of making all WPF applications look consistent with each other when a good number of them use custom styles anyway. All the investment in time and money for styling applications is wasted by an inexplicable "by design" decision. Now a custom a styled ListBoxItem or ComboBox looks even more out of place thanks to this flawed decsion.
Posted by Microsoft on 6/26/2012 at 4:02 PM
Also, the difference you're seeing between targeting 4.0 and 4.5 can be affected by a compatibility flag. If you set
FrameworkCompatibilityPreferences.AreInactiveSelectionHighlightBrushKeysSupported = false;

early on in your app (e.g. in MainWindow.ctor before calling InitializeComponent), you'll get the 4.0 behavior.
Posted by Microsoft on 6/26/2012 at 3:54 PM
The designers of the AeroLite and Aero2 themes (the new themes for Win8) chose new colors and appearance for the selection feedback in ListBox, rather than using system colors. Sadly, they did not do so in a way that allows you to override their choices. WPF must honor their colors, to be consistent with other Win8 applications.
Posted by Microsoft on 6/25/2012 at 5:13 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Microsoft Visual Studio Connect Support Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 6/24/2012 at 3:54 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.