C# WPF VS2017 - Forcing Aero theme - c#

I'm trying to fix a rendering issue with a WPF app (a screensaver) that I wrote using VS2015 on Windows 7.
On Windows 10, the config window looks totally different and, more importantly, it's almost useless because of how it renders in Windows 10.
Here are some screenshots. First, windows 7
And Windows 10
While there are lots of little differences, and I expect that, what's unforgivable is the coloring and cut off controls. Check boxes are checked and you can't tell. Radio buttons are selected and you can't tell. You can't even see the bottom control. It's garbage.
I did some research and found that I could override the theme, forcing the use of Aero. I don't know if that will fix my problem and I'm having trouble making it work.
According to my research, if I add the following to App.xaml, it may fix things.
<Application.Resources>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
<ResourceDictionary Source="pack://application:,,,/WPFToolkit;component/Themes/Aero.NormalColor.xaml" />
</Application.Resources>
But, doing that gives me a warning in VS2017:
The property "Resources" can only be set once.
So, I can't even test it. I have yet to find a way around this. How do I make it work?
---------- UPDATE 1 ----------
With help from comments I got to:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
However, now the app will not run at all.
Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code).
Original source on GitHub

You are hard coding the size of the Config window.
Height="358" Width="300"
That's not going to render correctly on modern OS's, where the user has changed the DPI scaling.
In this case it might be better to use the Window SizeToContent property
SizeToContent="WidthAndHeight"
SizeToContent documentation

Related

ResourceDictionaries - StaticResource - other assembly

I'm currently trying to figure out how I can get the WPF designer to display correctly a list of resources I can use.
For example when using a TextBlock in xaml, I can "preview" the useable resources, for usual.
This does not seem to work well when using it from an external DLL/assembly (binary).
I've already tried to use the usual source strings for ResourceDictionary,
<ResourceDictionary Source="pack://application:,,,/MyAssembly;component/Themes/Generic.xaml"/>
<ResourceDictionary Source="/MyAssembly;component/Themes/Generic.xaml"/>
as mentioned in various other questions and answers while googling this issue, though not even the direct Uri to the required ResourceDictionary seems to work.
Is there any fix for this issue or does it simply not work ?
I don't want to disable the designer, please do not suggest so.

Is there a way to make WPF application less "ugly" in Windows 10?

So, I just switched to Windows 10 and I noticed all my desktop WPF applications are noticeably "uglier" than they where on Win7/Win8.
I know this sounds subjective/pointless, but let me be more precise. Here's some examples of objective degradation of the UI's usability/clarity:
Everything looks like Windows 95, all gray without shading of any kind, almost like there's a custom theme (or a default theme is missing or something)
A lot of disabled elements do not get "grayed out" (see image below)
Disabled buttons do not get flattened (again, see image)
ListView items are not highlighted on mouseOver
ProgressBars have the "blue segments" pre-XP look
etc.
Is this "normal", i.e: is this the new default WPF theme?
If so, can I change it? It's really bad
If not, what am I missing?
EDIT:
After testing on another machine, turns out the problem had nothing to do with WPF or Windows.
Just DON'T apply any tweaks for win10 you find on the internet to restore the coloring on windows borders. It messes up the WPF theme engine.
Sorry for wasting your time guys.
Well, I found out how to fix it (thanks to gix for pointing me in the right direction):
First step: reference the PresentationFramework.Aero2 assembly in your project
Second step: add the following to your App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero2;component/themes/Aero2.NormalColor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Now it looks like it does in Windows 8. Note that you can also use Aero instead of Aero2 if you want the Windows 7 look (also change the referenced dll of course!), but I think Aero2 looks much more "native" on Win10.
EDIT:
After further testing, turns out this is not 100% perfect, although it's close enough. For example: disabled text boxes are not grayed out, and ListViews seems to not be affected at all, they still look like they crawled out of Windows 98's ass... if anyone has a clue on how to make the Aero2 style stick to them as well it would be great

How is the default template of a custom control applied with out using "Themes\Generic.xaml ?"

I created a custom content control with its default template.
The template though is not located in the location "Themes\Generic.xaml" as it is supposed to be. Instead I placed it in a separate resource dictionary with a different name.
It is merged along with other resource dictionaries in the App.xaml resource dictionary.
Running the code yielded no errors and the control is visible. I tested the application on other machines and the code ran just fine , I would like to point out that these machines are development machines.
Testing the application on the client machines (non development) then revealed some strange behaviour. The custom control was not visible; it would only be visible on 1 out 3 client machines.
I was able to fix the problem by putting the template in "Themes\Generic.xaml".
My question is how was it able to work without having to put the template in "Themes\Generic.xaml" ? I have searched on Google but I could find any clear cut explaination .
Thank you
For your templates to be applied they need to be present in Themes\Generic.xaml.
The good news is that you may merge them here, which I find to be good practice, and makes your code cleaner. Often my generic.xaml consists of only this, one X.Generic.xaml for all your cust. controls.
Themes/Generic.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...>
<!-- Your custom controls split into separate files -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/YourNamespace;component/Themes/ControlA.Generic.xaml" />
<ResourceDictionary Source="/YourNamespace;component/Themes/ControlB.Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

The name "RichTextBox" does not exist in the namespace "http://schemas.xceed.com/wpf/xaml/toolkit" [duplicate]

I've been trying to use the Extended WPF Toolkit so that I can make use of the RichTextBoxFormatBar but I seem to be going round in cirlces. Despite trying several examples on here and other sites I keep getting the same error messages:
The attachable property 'FormatBar' was not found in type 'RichTextBoxFormatBarManager'.
The type 'toolkit:RichTextBoxFormatBar' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
I'm new to WPF so I'm know it's something I'm not picking up on rather than a bug, can anyone tell me what I'm doing wrong and save my sanity?
<UserControl x:Class="TestWPF_Richtextbox.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<RichTextBox>
<toolkit:RichTextBoxFormatBarManager.FormatBar>
<toolkit:RichTextBoxFormatBar />
</toolkit:RichTextBoxFormatBarManager.FormatBar>
</RichTextBox>
</Grid>
</UserControl>
EDIT: Both the library and the project are .Net 4. The version of the WPFToolkit.Extended.dll is V.1.6.0.0.
My own stupid fault.
I'd forgotten to unblock the DLL when I downloaded it as per the instructions which say that after downloading the ExtendedWPFToolkit_Binaries.zip you should then right click on it, select "Properties" and then "Unblock".
Hopefully this post will help someone else who has made the same mistake.
I'm hardly a rookie - but had the same issue.
Frankly I've never heard of unblocking a .zip file. Like most people I just skimmed the instructions, after all I know how unzip a file - or so I thought.
I had fought with extended toolkit 1.9.0 for two hours because my app would compile, run and work, but VS12 designer couldn't render the window. THen I saw the above post about unblocking the zip before expanding. Thought to myself "whiskey tango foxtrot" is this guy talking about. But I was desperate, so I closed VS. Deleted my expanded files. This time did the unblock. THen expanded into the very same locations. Restarted Visual Studio and to my amazement the designer now renders the controls and don't complain about the WatermarkTextBox not being in the namespace etc.
Really a humbling experience about reading the directions more closely.
This same thing happened to me and I eventually figured out it was either because I had the dll or the solution stored on the network instead of my local computer. I moved both to the local computer and it started working.

In WPF, How to apply style to UserControl in design view?

I usually define style and control template in App.xml under tab.
So, while designing the UI, I can see the UI with the style applied in design view in Visual Studio 2008 with .NET3.5.
However, in another case, sometimes I make UserControl only project and in that case, there's no App.xml so the UI is appeared as default appearance in design view. It's hard to know actual looking in runtime.
Is there any way to apply style to UserControl, too?
If there's a way to share same style and template between application project and UserControl project, that would be perfect!
Please let me know if there's a solution.
You can keep your styles in a separate ResourceDictionary in your control project. Then you need to Merge Dictionaries in the Resources block at the top of every user control:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyControlLibraryStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
The problem with this approach is of course that you lose any benefit that App-level styles would give you (like styling differently for different applications) because now the styles are all determined by the underlying control.

Categories

Resources