How to prevent overriding from button styles in WPF - wpf

out current application is a DevExpress Ribbon window. However, we have some legacy code - including a WPF Control which was hosted through a WinForms Window - with WPF Host. (please dont ask why)
I wanted to change the UserControl at least to a Wpf Window to get rid of WinForms.
Now here is my Problem: All stlyes get totally messed up. Especially my buttons have a problem:
The buttons lose their assigned Images, and also Background and Foreground is not assignable. Through the Live Visual Tree from Studio I see that it is overridden.
I guess the thing with images leads to the same root cause.
I dont want to redo the whole window again in DevExpress (if this is the cause).
Is there a way for a window to not use some application styles and run as default? Or how can I find out, what is actually overriding everything?

I finally found the solution. The DevExpress was overriding any styles of any form in application, settings something to the DevExpress.Xpf.CoreTemeManager.
To disable a style, I had to add the following thing to my window:
<Window x:Class="AnotherWindow"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
dx:ThemeManager.ThemeName="NoneName"
<!-- ...-->
</Window>
Also include DevExpress.Data and DevExpress.Xpf.Core references.

Related

What should I implement for a small popup control in a VSTO project?

In my VSTO projects (Office 2007 / 2010) I would like to use a small popup control (think Tooltip like features; fade animation and mouse interaction).
I would prefer to use WPF. If I were to do this in WPF I would create a custom Popup Control.
In VSTO, as far as I understand it, I must use a WPF window and then have 2 options, either I put this window in a Windows Form Container or I get the Hwnd of my office app and I add this Hwnd to the Owner property of a WPF Window. Am I correct here?
Creating a whole window, animating it on and off the screen etc to look like a ToolTip seems to be overkill.
So my question is how should I do this. I would prefer WPF.
I don't know if this would work but my first thought is to build a very tiny WPF window which is transparent and start it with the Office App. I can then build a Popup Control (which is a child of this tiny window) which I show and not show at a mouse position. Pretty sure a popup can appear outside the bounds of its parent window.
Just wanted to tidy up my own question with what I did. In the VSTO addin project I added a reference to WindowsBase, PresentationFramework and presentation core.
And then I just follow any tutorial or example that adds a WPF Popup. By popup I mean a System.Windows.Controls.Primitives.Popup. For the Placement I used PlacementMode.Absolute and then used a window point to set its position.
This pretty much answers my question. Of course this popup is literally floating above your office window so you will need to make sure that you control it for example if the office window moves, is minimized and the like.

Image Control disapear after it's dragged in Design

I'm a WPF newbie and, unlike WinForms, I have a hard time to setup things in the design window.
My first obstacle is the Image control. After I drag it in the Design window it disappears and there's no way for me to edit its properties (like with the button control for example). The only way to make changes is via the XAML code which isn't very visual and intuitive.
Is there a way to keep editing the Image control in design mode? (example, move it around, select it to view its property panel, etc.)
All you should need to do is give the image control a fixed height and width and it should stay in the designer.
The best thing about the XAML is which separated from code for better re usability like asp.net. It's best you to learn different layouts such as grid, wrappanel, stackpanel etc. Then, you will feel the power of xaml. Else, you can choose the XAML building tools.
Link to refer

How can I style the border and title bar of a window in WPF? [duplicate]

This question already has answers here:
How to create custom window chrome in wpf?
(5 answers)
Closed 6 months ago.
We are developing a WPF application which uses Telerik's suite of controls and everything works and looks fine. Unfortunately, we recently needed to replace the base class of all our dialogs, changing RadWindow by the standard WPF window (reason is irrelevant to this discussion). In doing so, we ended up having an application which still looked pretty on all developer's computers (Windows 7 with Aero enabled) but was ugly when used in our client's environment (Terminal Services under Windows Server 2008 R2).
Telerik's RadWindow is a standard user control that mimicks a dialog's behaviour so styling it was not an issue. With WPF's Window though, I have a hard time changing its "border". What I mean by "border" here is both the title bar with the icon and the 3 standard buttons (Minimize, Maximize/Restore, Close) and the resize grip around the window.
How can I change the looks of these items:
Title bar color
3 standard buttons
Window's real border color
With round corners if possible.
Those are "non-client" areas and are controlled by Windows. Here is the MSDN docs on the subject (the pertinent info is at the top).
Basically, you set your Window's WindowStyle="None", then build your own window interface. (similar question on SO)
You need to set
WindowStyle="None", AllowsTransparency="True" and optionally ResizeMode="NoResize"
and then set the Style property of the window to your custom window style, where you design the appearance of the window (title bar, buttons, border) to anything you want and display the window contents in a ContentPresenter.
This seems to be a good article on how you can achieve this, but there are many other articles on the internet.
I found a more straight forward solution from #DK comment in this question, the solution is written by Alex and described here with source,
To make customized window:
download the sample project here
edit the generic.xaml file to customize the layout.
enjoy :).
Such statements as “you can't because only Windows can control the non-client area” are not quite true — Windows lets you specify the dimensions of the non–client area.
The downside is this is only possible by calling Windows' kernel methods, and since you're in .NET, which is not native code, you'll need P/Invoke. (Remember, the whole of the Windows Form UI and console application I/O methods are offered as wrappers that make system calls under the hood.) Hence, as documented in MSDN, it is completely possible to use P/Invoke to access those methods that are needed to set up the non–client area.
Update: Simpler than ever!
As of .NET 4.5, you can just use the WindowChrome class to adjust the non-client area. Get started here and here, a guide to changing the window border dimensions. By setting it to 0, you'll be able to implement your custom window border in place of the system's one.
I suggest you to start from an existing solution and customize it to fit your needs, that's better than starting from scratch!
I was looking for the same thing and I fall on this open source solution, I hope it will help.

Adding Custom Windows Controls on WPF User Control

I have a WinForms User Control (a toolbar) which i would like to add on a WPF user Control, is there any way to do this?
like i want a WinForms User Control (the toolbar) along with other WPF Controls
(datagrid) on a new WPF User Control
I saw a couple of samples that show Windows Forms hosted in a WPF Control. But that is not what i want to see.
This is pretty easy to pull off. There is a handy little thing known as WindowsFormHost all you have to do is declare it in your control's XAML, and nest your forms control inside of it, like so:
<UserControl>
...
<Grid>
<WindowsFormsHost>
<forms:MyFormsToolbarControl/>
</WindowsFormHost>
</Grid>
...
WindowsFormHost lives inside of the normal WPF toolbox so it shouldn't be hard to locate. Meanwhile there is an example of how to produce the equivalent XAML in code at this location...
http://msdn.microsoft.com/en-us/library/ms751761.aspx
You can check out my answer to a similar question here:
WPF hosting a WinForm, Tab Navigation problems
This will also show you how to fix a tabbing issue with windows controls that are sitting inside wpf views.

Dynamically adding ElementHost'd WPF UserControl to WinForms results in Black

I have a WPF user control inside an ElementHost that is inside a WinForms control to wrap it. I'm dynamically adding it to a tab control tab.
But when I do this, my WPF control is black.
How do I fix that?
There are many alternative solutions on the web to this one. However, what fixed it for us was to avoid "Fill" docking the element host within it's parent control. If you are using docking, then give it a try!
Unfortunately this can be one of those evil problems solved by experimentation and it'll turn out to be a one line fix!
It was my own mistake. I forgot to add the WinForms tab control panel (a 3rd party one) to the right class.

Resources