Font changes between design time and runtime (VS 2010 and wpf) - wpf

When I create a window or custom control with wpf inside Visual Studio the default font used is Segoue UI 12 (at least on Windows 7). When I execute the application the font really used is Verdana 13, a bit greater, so some signs are cut and the user experience is a poor formatting look and feel. Don't know how to change the default font inside VS 2010 and if it is the best way to achieve the goal of aligning what I see during the design phase and what the user will see at run time.
I checked for the word 'Verdana' in the entire solution and it was not found so I'm quite sure this weird behavior is not due to a style which is applied as a dynamic resource.
Thanks for any help
Filippo

By default, WPF uses system font in runtime. If you want to always use Segoe UI, you can set FontFamily property to "Segoe UI".

Related

Does Win32 Common Controls use Direct2D now?

I have a Direct2D app where I draw text messages with DirectWrite. It's all C++. I want to add an edit control which must support emojis and a button on the right. Does Win32 edit controls and buttons can be used in a Direct2D window and is the text button rendered with DirectWrite or with the old GDI?
Thanks you
No GDI-based common controls in comctl32.dll use DirectWrite to draw text (too many compatibility concerns), but many newer parts of the Windows 10 shell use DirectWrite - anything based on DUI or XAML, like the Start menu or system Settings app.
Per Simon Mourier's comment, I wrote an SDK sample years ago called PadWrite that demos a very basic edit control, but I can't recommend it as a serious text editor because it recreates the IDWriteTextLayout object every edit. So it's best for just a few lines or paragraphs of text, as a smarter editor would selectively update only the parts of the text that changed. This works on Windows 7, but Windows 7 itself had only basic emoji support (monochrome glyphs in Segoe UI Symbol). Not until Windows 10 (with Segoe UI Emoji) did it really become colorful.
The newer RichEdit is also a viable option (I forget which flags enable it).
I've tried to subclass the standard EDIT control to intercept WM_PAINT messages (along with Edit_GetRect, GetDCEx, DefSubclassProc), but that's brittle because the HFONT does not always match the same metrics as the corresponding IDWriteFontFace due to font fallback and metrics differences between GDI vs DWrite, meaning your drawn text may not match the glyph advances the underlying EDIT control uses.
WinUI should work nicely if you can take a dependency on >= Windows 10.
There's also the Scintilla text editor which supports a DirectWrite mode. https://www.scintilla.org/ScintillaDoc.html (set SCI_SETTECHNOLOGY = SC_TECHNOLOGY_DIRECTWRITE). This will work on >= Windows 7 (or Vista with SP2 Service Pack Platform Update).

Change Visual Studio 2012 WPF Forms Designer Background Color

I, like many developers, like to have dark background and light text - so I use the "Dark" theme on Visual Studio. However, when developing an application for WPF (which I admittedly do less often than I should), I have noticed that this has an unintended effect of making my controls difficult to read.
Thinking there is an easy solution out there, I tried changing the fonts/colors in VS, to no avail. There does not seem to be a color property for the WPF forms designer background color. The answer to this question does not seem to be applicable to either VS 2012 or Windows 7 (not sure which), as I did experiment with the control panel but did not find a suitable setting.
Does anyone know how to make the background a different color (ideally, a medium gray in this case)? See screenshot.
I'm not sure about 2012, as I have 2015, but I had a similar issue and found the appropriate settings here in tools->options->Environment->Fonts and Colours and select the XAML Designer:

Should I care about current theme?

Authoring a WPF control template, consisting of only a Grid, some TextBlocks and a couple of Buttons, do I really need to worry about the current theme on user's machine? Will it look crippled or otherwise imperfect on a machine running on Win8? I do not have access to a Win8 machine, so can't ensure, but this forum post suggests that "simple" controls are not affected by the current theme. If that is the case, which controls are included in the list of simple contorls?
I believe all standard controls come without any styles applied to them on Win8.
Update:
I am sorry it looks like I was wrong. There is a specific Theme for Windows 8. It is called Aero2.NormalColor.xaml
You can find more info about it here:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e3dd4221-af4d-4ae4-a983-895db12ebcd0/what-is-the-theme-name-for-a-wpf-application-on-windows-8
Here is where to find the theme file itself:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d05228d4-3dc2-4241-84a1-236a7a1f2d65/where-is-the-xaml-source-for-the-aero2normalcolor-theme
More here
http://brianlagunas.com/add-windows-8-aero-theme-support-to-your-wpf-custom-control/
Update 2:
And here is how to force your application to use specific Theme ignoring windows version:
http://www.kennethham.com/wp/2010/11/force-wpf-to-use-windows-7aero-theming-in-classic-mode/

Why WPF renders differently on different versions of Windows?

I read that WPF uses DirectX under the hood to perform its rendering, that it doesn't rely on the dinosaurian libraries that WinForms uses to render controls.
So I made my Presentation layer with WPF and it looks the way it should under Win8.
Then I deployed the project to Windows Server 2003... to find out that my nice little custom message box looks awfully WinForms-like and somewhat clunky; the button controls are VERY similar to the WinForms ones, the expander control is no longer shown as a circled ^ arrow and looks like it was drawn in 1998 (picture the ^ arrow on an ugly square flat button that pops up when your mouse hovers over it).
From the Pro WPF in C# 2010 Bible:
Part of the promise of WPF is that you don't need to worry about the details and idiosyncrasies of specific hardware. WPF is intelligent enough to use hardware optimizations where possible, but it has a software fallback for everything. So if you run a WPF application on a computer with a legacy video card, the interface will still appear the way you designed it.
So, is this a lie? To me it is, because it doesn't appear the way I designed it.
If not, then why/how doesn't the thing render identically regardless of the machine that's running it? Is the software fallback somehow designed to mimick Win32/GDI rendering? Is there a way to get my little custom message box to look identical on Win8 and WinServer2K3?
That has NOTHING to do with DirectX / Rendering / video card / any of that.
and EVERYTHING to do with WPF taking the DEFAULT appearance of ALL UI Elements from the Windows Theme.
If you don't want this behavior, you'll have to provide Styles and Templates for ALL UI element types, or otherwise find a way to include PresentationFramework.Aero.dll in your application and use that as the default theme library.
Take a look at this answer

Font changes during the runtime in WPF app

I'm using a non English (Hebrew) font in a WPF application. The font was embedded in the project by expression blend.
In the designer I see the font correctly, but during the run time part of the letters are being changed to different font style.
What could it be?
Are the design and runtime environment on the same machine ?
If not, check for installed fonts.
If it's on the same machine, then maybe check if some localization happens on during runtime.

Resources