MahApps.Metro icon indicating copy to clipboard operation
MahApps.Metro copied to clipboard

ClearType partially not working

Open BerndK opened this issue 12 years ago • 18 comments

I want to see ClearType on all my Controls as far it is possible (not possible with some sorts of clipping, opacity, fading ...). The grayscaled antialiased text is a pain in the eyes which cannot be accepted in professional apps. I'm just using the MetroWindow with standard controls like TextBlock, Label and TextBox. First thing I does not understand, is that ClearType is not enabled by Default. So the only special setting I do is RenderOptions.ClearTypeHint="Enabled". Now the TextBlock and the small Label shows up correct - the long Label and the TextBoxes does not! Result: image (see the coloured pixels versus the grayscaled ones)

Code to reproduce:

<controls:MetroWindow x:Class="MetroClearTypeTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
        Title="MainWindow" Height="350" Width="525"
        RenderOptions.ClearTypeHint="Enabled"
        >
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="137*"/>
            <ColumnDefinition Width="380*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0">
            <TextBlock TextWrapping="Wrap" Text="ClearType Test" />
            <Label Content="Small Label Text"></Label>
            <TextBox Text="Text Of TextBox"></TextBox>
            <Label Content="a veeeryyy loooong Label Text"></Label>
            <TextBox Text="Text Of TextBox"></TextBox>
        </StackPanel>
    </Grid>
</controls:MetroWindow>

If you change MetroWindow to Window, everything looks fine. I saw the issues #889 and #1156 but this doesn't help - as far as I understand the problem should be fixed in current version. This my Environment: Using latest Version of MahApps from Nuget 0.14.0 (same problem with current clone),VS2013, Win 8.1 Thanks for any comment ;-)

BerndK avatar Sep 01 '14 11:09 BerndK

@BerndK try set TextOptions.TextFormattingMode="Display" too

punker76 avatar Sep 01 '14 12:09 punker76

Hi Jan, sure I tried

TextOptions.TextRenderingMode="ClearType"
TextOptions.TextFormattingMode="Display"

but nothing helps.

BerndK avatar Sep 01 '14 12:09 BerndK

@BerndK don't know what's going wrong with your code. i've tested it with a simple mahapps window and for me it works...

2014-09-01_14h51_37

it exists many reasons why ClearType not works...

http://blogs.msdn.com/b/text/archive/2010/01/15/cleartypehint.aspx http://arbel.net/2007/02/03/give-me-back-my-cleartype/

punker76 avatar Sep 01 '14 12:09 punker76

Hi Jan, you are cheating ;-) in my example the space for the label wasn't enough (the text was veeeryy looong), in your example the label has more space (no clipping) and it works (the same as my first Label). Anyway your Textboxes are NOT ClearType, they are antialiased (gray pixels), but not coloured ones (ClearType). image This is a zoomed part of your picture!

As you can see the TextFormattingMode does not change the view. Hint: I use the screen lens with 300% then you can see very quick what's going on. (start the screen lens by typing "Center für erleichterte Bedienung" on a german Windows.)

BerndK avatar Sep 01 '14 17:09 BerndK

Hmm... this issue seems to be specific to TextBox in this case. Works fine for Label and TextBlock though. The RenderOptions.ClearTypeHint="Enabled" set at Window-level isn't being applied to TextBox.

mahara avatar Sep 01 '14 17:09 mahara

Sorry, but the Label and TextBlock only works as long as there is enough space. If the content is clipped (because not enough space to write all the text) there is no more ClearType. Using the lens you can see that there are many other Controls that are not ClearType, when you examine the official Demo App "MetroDemo.NET45". To see this, first you have to switch ClearType on with RenderOptions.ClearTypeHint="Enabled"

BerndK avatar Sep 01 '14 18:09 BerndK

Whoa... nice observation on the clipped contents! I didn't notice them earlier... :) Makes me wondering what the root cause of this issue on those problematic controls is... Is it Opacity?

mahara avatar Sep 01 '14 19:09 mahara

@BerndK maybe i found it. the WindowChrome (WindowChromeWorker) sets the background to transparent.

                // Apply the transparent background to the HWND
                //_hwndSource.CompositionTarget.BackgroundColor = Colors.Transparent;

if i comment the line, the cleartype comes back... 2014-09-01_23h03_43

punker76 avatar Sep 01 '14 21:09 punker76

@BerndK i will try it tomorrow on a win 7 system (tested actually under win 8.1), if it works without any side effect, then i should change it.

punker76 avatar Sep 01 '14 21:09 punker76

These are good news. Now it seems that I have found a really cool Theme for professional looking (and readable) apps. Thanks for all the work Jan.

BerndK avatar Sep 01 '14 21:09 BerndK

Whoa! Right on. And ClearType suddenly correctly applied. Even without explicitly setting RenderOptions.ClearTypeHint="Enabled"... :D

Would that have any side effect?

mahara avatar Sep 01 '14 21:09 mahara

I've tested your last modification. Almost everything of the DemoApp looks correct. The only thing I saw was the ComboBox: combobox Here the Value of the comboBox looks OK, but the List is not ClearType. This topic is not mission critical, because most time comboboxes are closed.

BerndK avatar Sep 02 '14 08:09 BerndK

@BerndK that's an issue by the combobox itself, the popup uses AllowTransparency="True" to work with non aero windows themes. but this breaks always the clear type!

punker76 avatar Sep 02 '14 09:09 punker76

@BerndK @mahara no time to test #1537 ?

punker76 avatar Sep 03 '14 12:09 punker76

OK, I'll take a look at it. Thanks.

mahara avatar Sep 03 '14 13:09 mahara

@punker76 Just tested it, and the fix seems to be working to me. Also it's that actually fixes my previous issue (https://github.com/MahApps/MahApps.Metro/issues/889) when ClearType doesn't get applied on DataGrid, ComboBox, and ListBox. Thanks a lot, Jan!

mahara avatar Sep 03 '14 13:09 mahara

I tested it, everything (including ComboBoxes and menuItems) is looking pretty fine now. I would suggest to remove the left comments in Controls.ComboBox.xaml and Controls.ContextMenu.xaml or are thy still needed?

Sorry for my delay, I'm in holidays and therfore only partial online and only limited time at the machine ;-)

BerndK avatar Sep 03 '14 18:09 BerndK

@BerndK no worries! i remove the comments and put a simple guide to the mahapps page.

punker76 avatar Sep 03 '14 18:09 punker76