Why is my RibbonWindow not themed correctly? - c#

Working with the ribboncontrolslibrary, when I run my application the title bar looks like W98 application,. How can I make it look pretty?
Edit: It seems that has something to do with the theme used on windows.
any help would be appreciated.
alt text http://img718.imageshack.us/img718/8188/321321.jpg
<r:RibbonWindow x:Class="Produccion_Dampers.main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="Window1"
Height="600"
Width="800">
<DockPanel>
<r:Ribbon DockPanel.Dock="Top" Title="my App looks like s***t">
</r:Ribbon>
</DockPanel>
</r:RibbonWindow>

(from my previous comment)
You can draw a custom window frame as described in this MSDN article: http://msdn.microsoft.com/en-us/library/bb688195(VS.85).aspx, which includes information about drawing the window caption with the system theme's font (which might provide clues about accessing other theme information).

If you are running a custom theme on your machine, WPF windows default to the "Classic" theme.
As I understand, your options are then limited because the title bar is non-client to your application -- it is rendered by the OS (why then it can't adopt the custom theme, I don't know).
you can use p/invoke to do some nasty stuff
you can create a borderless window and fake the title bar yourself
you can see if the (rather old) info here does anything good for you : http://www.browsoft.com/tutorials/DefaultTheme.html
(If the last one works, it means my understanding about rendering the title bar is incorrect.)

Related

How can hide the opened child windows from taskbar (WPF)?

How can hide the opened child windows from taskbar when I am showing and hiding the child windows even when I hide the child window the hidden window still appear in the taskbar WPF?
Thanks in advance,
Here is an Example how I show the dialogs:
AlignLocalAxisView alignLocalAxisView = Container.Resolve<AlignLocalAxisView>
(new ParameterOverride("model", AttributesSelectedItems));
OpenedWindowView = alignLocalAxisView;
alignLocalAxisView.Show();
There should be a ShowInTaskbar property for the window.
If your window is defined in XAML, you can set the property deliberately as shown below:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="MyApplication.MainWindow"
Title="MainWindow"
Height="350" Width="425"
ShowInTaskbar="False">
You can also set this in your code behind:
this.ShowInTaskbar = false;
This is also applciable to a window created in code behind when called by name.
Window myNewWindow = new Window();
//Set the property to keep the window hidden in the task bar
myNewWindow.ShowInTaskbar = false;
//Then, show the window
myNewWindow.Show();
EDIT: Based on your example code, the following should work
AlignLocalAxisView alignLocalAxisView = Container.Resolve<AlignLocalAxisView>(new ParameterOverride("model", AttributesSelectedItems));
OpenedWindowView = alignLocalAxisView;
//Assuming your view extends the Window class, the following will work
alignLocalAxisView.ShowInTaskbar = false;
alignLocalAxisView.Show();
Hopefully, this will be enough to sort the problem out.
For future reference though, this was a fairly quick solution to look up on google - its generally worth searching for an answer first as it can sometimes be a faster way to solve the problem.
in this case, I reworded your issue to "hide task bar icon for window in wpf". The child window part wasn't really needed in the search, as all windows in WPF are basically the same.
I hope that's of some help.

NavigationWindow class: remove navigation bar and maximized NavigationWindow

excuse me for my bad English.
I know that many conversations were made ​​for this type of problem but none answer my specific problem...
I am currently improving a Wpf Application coded in C # and xaml in Microsoft Visual Studio Express 2012 for Windows Desktop.
I would like to remove the navigation bar at the top of my window and maximize it. In my xaml file I do:
NavigationWindow x:Class="WpfAppTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowState="Maximized"
WindowStyle="None"
Title="MainWindow" Height="980 " Width="540" Source="Home.xaml" />
Despite WindowState= "Maximized" and WindowStyle="None" the navigation bar is still displayed and the window is still small. I followed several tutorials that removed the navigation bar, but they used a Window class. I did some tests on a new project by creating a class Window and I can well maximize and remove the navigation bar from my window.
But in my case I need to improve an application in progress but the main window type is MainWindow
Indeed the source Source= "Home.xaml" is no longer recognized after the change Navigation Window to Window. My application contains several pages and I must navigate through it so I have to keep my "Home" type "page" page: <Pagex:Class = "WpfAppTest.Home".
Do you have any idea where my problem may be?
Thanks you in advance.
Geoffrey
You can host a Frame in your Window. That is essentially what a NavigationWindow does.
MSDN has more info on navigation hosts.

Custom ContentControl in WPF

I think I'm asking for a lecture on the proper application of WPF here but I'm going to take my chances since I'm at my wit's end. I think this is probably largely a result of my lethargy in fully embracing WPF templates and styles so I'm happy to listen to any such lectures.
I'm writing a sort of audio editor / event orchestrator. I've got a track editor that I'm fairly happy with. However, I built it largely out of custom controls (I know, this is probably a WPF sin). In keeping with that theme, I want to make a standard header for the tracks but I want the individual track "types" to be able to define what goes in that header. I thought a control that defines a sort of "grip" on the edge and then allowed the implementer to "fill in" the substance would work well. However, I have no idea how to do this in WPF without using styles and even if I end up using styles, I would like to understand this.
This probably comes down to wanting a sort of exemplar implementation of a simple ContentControl control (e.g. a button) and not being able to find one (other than AvalonDock, which ultimately uses - correctly i'm sure - templates for this). In my head, the xaml looks something like this:
<ContentControl x:Class="TestArea.CustomContentControl2"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Hello"/>
<ContentPresenter Grid.Column="1"/>
</Grid>
But of course, that doesn't work. I'm fairly sure I could pull the same thing off by playing tricks with overloads behind the scenes, but it would be nice if I could do something like this. Do I really have to put all my terrible, procedural ways behind me and use these styles you speak of? If so, can someone at least tell me what that button looks like down in the framework?
Here is a complete example of deriving from ContentControl to accomplish what you want: Creating Customized UserControls (Deriving from ContentControl) in WPF 4
Pete's ContentPresenter is doing the same thing as it does in your example.
Using styles allows you to seperate functionality of a control with representation of a control; such as the Button.
Think as a control at the start as nothing more then functionality. A simple class containing predefined events, properties, etc... Once that control takes on the job of becoming part of a visual tree it now needs a visual identity. It didn't need one previously; however now it does. Defining a default style allows that control to now have a visual representation which it did not need prior as it was not living within the visual tree.
Ignoring styles would be like ignoring CSS when making use of HTML.

WPF: Textbox scrollbar has no thumb

My textbox is the only control on a window, which is a part of a bigger application. The textbox contains a certain amount of text, large enough to show vertical scrollbar. The scrollbar appears, but without a thumb:
I can still scroll the contents, either with mouse wheel or by clicking the arrow-buttons repeatedly.
When I create a new project with the same window and textbox the scrollbar works as it should. The same happens with a WrapPanel. Do you have ideas what could be spoiling my existing project and causing this issue? In generic.xaml I found some styles overriding the defaults for scrollbar and scrollviewer, but even totally clearing generic.xaml didn't help.
Thanks in advance!
EDIT: right, the code. It's XAML only (no c# backing code).
<Window x:Class="TextBoxTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" MaxHeight="200" MaxWidth="200">
<TextBox x:Name="textbox" MaxLines="2" MaxHeight="50" VerticalScrollBarVisibility="Auto" TextWrapping="WrapWithOverflow">
Useless text..... asdasdasda ssssssssssssss sssssss ssssaokdoka sdojwoandowm nxaofwha398ua ozmca3u0a3j3 a80a9fu 03 u0sf u0s9jf4s 0cuj wuf0j w40 fcjw cujwfj9 c9 u49 wsuc j9w3
3089w 9f8u4wfv 0sf ufw0u w0fuw0 fwu f0uw 09djcazp zopf h43 wofh FYHFWFH WOWY HWO H wohg fujg 4g fugj 4 g0 4
4w fw4 f3f g555u45y 55 some more some moresome more some moresome more some moresome more some moresome more some more.
</TextBox>
</Window>
The answer is astonishing!
Just after I'd started to suspect it might be a WPF bug, I found this forum thread.
Guy who asked the question says: "My application uses a directx renderer from a DLL that's written in C++". Mine does almost the same with the difference that my renderer is written in C# (MDX) and uses D3DImage interop.
Following steps mentioned in the thread above, I moved DirectX initialization from OnInitialize() to Loaded event callback of the main window and now scrollbars regained their expected appearance. It seems that GUI must be displayed first, before the renderer is initialized.
So I guess it's reasonable to talk about a bug in this case.
It seems like a style problem. Remove explicit style setter from the TextBox (check both XAML and code behind). If TextBox has no explicit style, search for implicit styles (defined via TargetType="TextBox" or TargetType="{x:Type TextBox}" and/or x:Key="{x:Type TextBox"}).
Try snooping your application and check ScrollViewer's visual tree. It may give you some insights where to look.
Hope this helps.
At a guess: your TextBox is inside a StackPanel. If you want more than a guess, you'll need to provide code.
You can solve the problem adding CreateFlags.FpuPreserve during the creation of your D3D Device
Example:
this.device = new Device(0, DeviceType.Hardware, this.handle,
CreateFlags.HardwareVertexProcessing |
CreateFlags.PureDevice |
CreateFlags.FpuPreserve, this.pparams);

Wrapping Controls from System.Windows.Forms in System.Windows.UIElement

Is it possible to wrap the old System.Windows.Forms controls in System.Windows.UIElement? I know that the Browser Control is somehow wrapped and the base is from System.Windows.Forms.
If this is possible, would the implementation cause any consequences?
You can host a Windows forms control in your WPF forms. Just wrap it inside a WindowsFormsHost element. This shows how to host a windows forms masked test box in side a WPF window.
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="HostingWfInWpf"
>
<Grid>
<WindowsFormsHost>
<wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
</WindowsFormsHost>
</Grid>
</Window>
There is the WindowsFormsHost class, though I would add a note of caution. If you're using all your old controls from winforms, mixed with WPF, it won't be a nice experience for the user. I assume you've been told you can't, or don't have time, but really you should look to replacing your existing controls with WPF controls. Unless you have lots of seriously complicated owner-drawn stuff, this shouldn't be too much effort.
So my recommendation would be to start creating WPF versions of your existing controls (or buy a set from someone like Telerik for any non-domain-specific controls you've created, like toolbars etc), and only keep Winforms controls for extra-complicated bespoke controls you've created. Even then, you should be planning for a "phase 2" to replace those as well. Your users will thank you for it.

Categories