Is there any way to change the Minimize button, Maximize button, WPF window frame/border ect. using styles in the xaml?
These buttons are part of the Window Chrome, and therefore are supposed to be left for the user to decide on how they look (Windows has options for changing the color of the chrome). So if you want to take control of the Chrome, it is not as simple as a window style.
You can use the WindowStyle property to get rid of them, or make the window a Dialog-type window, but for more control, you'll need to get into creating custom chrome for your window.
If you want to go down this path, it is definitely possible, but you'll need to look at information about creating a custom chrome for your window. Here are a couple resources, but do your research and see which of these, or what other resources best meet your needs:
Code Project Library
Stack Overflow Answer w/ Links
MSDN Blog
You can remove the default Windows chrome with WindowStyle="None" and ResizeMode="NoResize" and then create whatever borders/buttons you like. E.g.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
ResizeMode="NoResize"
BorderBrush="Blue"
BorderThickness="5">
<StackPanel Orientation="Horizontal"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Height="20" >
<Button Content="Minimize" />
<Button Content="Restore" />
<Button Content="Close" />
</StackPanel>
</Window>
Related
I have a custom user control which contains ToolBar with buttons. I want these buttons and toolbar to be the base content of the control and assign it to different views. But for some views, in some cases, I need to add additional tools to the toolbar, or additional toolbar itself at the end of the already existing ones.
I tried control template and dependency property binding. In control template case I must move my already existing buttons from Content to template and that makes my buttons inaccessible from the code behind (I need to expose these buttons with public properties for other views to add event handlers on them later because different views need to have different responses on the same events).
As for the dependency property and ContentPresenter, well it just did not work and I have no idea why.
here is my XAML for UserControl:
<UserControl x:Class="Syllogia.Desktop.Controls.SylToolBar"
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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local="clr-namespace:Syllogia.Desktop.Controls"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="150">
<Grid>
<telerik:RadToolBar Grid.Column="0" Grid.Row="0" x:Name="MainToolBar" AutoHideOverflowButton="True">
<telerik:RadButton x:Name="AddButton">
<Image Source="icons/Pixel/plus_math_30px.png"/>
</telerik:RadButton>
<telerik:RadButton x:Name="EditButton">
<Image x:Name="ToggleButtonImage" Source="icons/Pixel/edit_32px.png"/>
</telerik:RadButton>
<telerik:RadButton x:Name="DeleteButton">
<Image Source="icons/Pixel/erase.png"/>
</telerik:RadButton>
<telerik:RadButton x:Name="PrintButton">
<Image Source="icons/Pixel/print_30px.png"/>
</telerik:RadButton>
<telerik:RadButton x:Name="RefreshButton">
<Image Source="icons/Pixel/refresh_32px.png"/>
</telerik:RadButton>
<Grid x:Name="GridAdditionalContent">
</Grid>
</telerik:RadToolBar>
</Grid>
question 1: Is there another way to add additional content to this control from the other controls?
question 2: Is there a way to expose buttons which are declared inside a template?
I am fairly new to WPF and there may be some detail which I was not able to search and find.
In any case, Thank you for your help and sorry if I am asking stupid questions here.
Problem Description
When using Touch(screen) input to operate a Button inside the Overflow of a WPF Toolbar the App stops responding to Mouse and Touch inputs. Keyboard input or any code execution (even in UI Thread) seems to be not affected.Moving the mouse outside the Windows content Area releases the freeze and the App can be used again (until one uses the Overflow again).
It sometimes it happens directly with the first interaction, often you can operate the Button a few times before the "freeze" happens.
The "freezing" does not happen when using the Mouse to access the Button inside the Overflow.
Test Environment
I made a small Test Project to verify it is not something in my App and I was able to verify the Problem for .NET 4.5.2, 4.6.1 and 4.7.
It has been tested on two different Windows 7 PCs with different Touchscreens. Both with the same outcome.
Code:
<Window x:Class="ToolBarTest.MainWindow"
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"
xmlns:local="clr-namespace:ToolBarTest"
mc:Ignorable="d"
Title="MainWindow"
Height="350"
Width="525">
<DockPanel>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Content="New" />
<Button Content="Open" />
<Button Content="Save" />
</ToolBar>
<ToolBar>
<Button Content="Cut" />
<Button Content="Copy" />
<Button Content="Paste" />
<Button ToolBar.OverflowMode="Always">
<Grid>
<TextBlock Text="Testbutton" />
</Grid>
</Button>
</ToolBar>
</ToolBarTray>
<TextBox AcceptsReturn="True" />
</DockPanel>
Additional thoughts
To me it looks like the Toolbar or the OverflowToggleButton is capturing the mouse device as soon as the Overflow Panel closes. Holding the Overflow Panel open does prevent the freeze (tested in my big App)
I crossposted the question on MSDN: https://social.msdn.microsoft.com/Forums/de-DE/c4e6061d-ecc1-4c7e-afe9-2587cfd2734d/fenster-bekommt-keine-maus-und-touchevents-mehr-nach-touch-interaktion-mit-toolbar-overflow?forum=wpfde
The second Link from the marked answer in above Thread helped me:
https://social.msdn.microsoft.com/Forums/de-DE/d964afd2-67d4-4dfb-b118-695ab07ef6c1/wpf-popups-and-touch-input-can-cause-ui-to-become-unresponsive?forum=wpf
Basically in the Click Event from the Button inside the Overflow I force the MouseCapture to the Button and Release it again:
Code Behind (not so emty anymore)
private void Button_Click(object sender, RoutedEventArgs e)
{
CaptureMouse();
ReleaseMouseCapture();
}
I use MetroWindow class from Mahapps to show dialog window of some kind.
My idea was to create auto resizable window, to fit it's content size
<controls:MetroWindow
...
DataContext="{Binding DialogVM, Source={StaticResource ViewModelLocator}}"
Title="{Binding WindowHeader}"
WindowTitleBrush="{StaticResource MainStyleTitleBrush}"
Background="{StaticResource MainStyleBackgroundBrush}"
wpfExtensions:SizeObserver.Observe="True"
wpfExtensions:SizeObserver.ObservedWidth="{Binding xHeight, Mode=OneWayToSource}"
wpfExtensions:SizeObserver.ObservedHeight="{Binding xWidth, Mode=OneWay}"
MaxWidth="1110" MaxHeight="1080"
MinWidth="450" MinHeight="600"
ShowMinButton="False"
ShowMaxRestoreButton="False"
BorderThickness="1"
BorderBrush="{StaticResource MainStyleBorderBrush}"
SizeToContent="Width"
WindowStartupLocation="CenterScreen">
<Grid>
<ContentPresenter Content="{Binding VM}"/>
</Grid>
</controls:MetroWindo>
but I have two issues
First one: My window is affected to user actions (Mouse double click on title, drag window to left or right screen edge, and so on), and I want it to be frozen, but resizable.
Second one: when I reshow the same window again (without recreating it, but with new content which can have new visible size) it show's on it's last position.
How can I solve this problems without code-behind WindowSizeChanged event catching?
put ResizeMode="NoResize" and SizeToContent="WidthAndHeight"
I am using the Ribbon control in WPF and I noticed there are 2 different versions.
using Microsoft.Windows.Controls.Ribbon;
If I use this one in my xaml and class, my whole window will be in a very old windows style.
using System.Windows.Controls.Ribbon;
If I use this one in my xaml and class, my Ribbontabs suddenly won't fill correctly anymore.
When I use both of them. With this:
<ribbon:RibbonWindow x:Class="WPSDashboard.Views.ShellWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism"
Title="WPSDashboard"
x:Name="RibbonWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Ribbon Region -->
<r:Ribbon x:Name="Ribbon" prism:RegionManager.RegionName="RibbonRegion">
<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu SmallImageSource="Images\SmallIcon.png">
<r:RibbonApplicationMenuItem Header="Exit"
x:Name="MenuItemExit"
ImageSource="Images\Exit.png"
Command="{Binding ExitCommand}"/>
</r:RibbonApplicationMenu>
</r:Ribbon.ApplicationMenu>
</r:Ribbon>
<Grid x:Name="ClientArea" Grid.Row="1">
<!-- Workspace Region-->
<GridSplitter HorizontalAlignment="Left" Width="2" Grid.Column="1"/>
<ContentControl x:Name="WorkspaceRegion" Grid.Column="1" prism:RegionManager.RegionName="WorkspaceRegion" />
</Grid>
</Grid>
</ribbon:RibbonWindow>
My Ribbontabs will load but the window now looks like this:
I can't click on close and minimize and maximize. <---
How can I get the border to be normal instead of small?
I can't close my windows this way.
I found the best way to make it look and work good!
Instead of the tags <ribbon:RibbonWindow on the beginning of the xaml,
Make it <Window .
Also add this part:
xmlns:r="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
Then in your class delete your : RibbonWindow (If it's there)
If that doesn't work and you don't need the quick access toolbar, this may help:
Go back to your XAML, and change the Ribbon margin to -22 :
<r:Ribbon x:Name="Ribbon" prism:RegionManager.RegionName="RibbonRegion" Margin="0,-22,0,0" >
Now my application looks like this(with the -22 margin) :
Now it looks like a normal application without an ugly windows 98 or 2000 style and the close button, minizime button and maximize button are back!
I personally would, either play on margins, or better than that, investigate the style of that ribbon and change it the way it helps my needs
I would like to write a C# app that runs like an overlay on the desktop wallpaper. Similar to the way that desktop widgets or Rainmeter(rainmeter.net) runs; behind other apps but on top of the desktop wallpaper.
I cannot find any C# examples of this kind of behavior. Can someone point to me to some code?
Here is an example of what I am interested in creating: http://jabz.us/uploaded_images/screenCaptureRainmeter.png
Why not just use WPF windows that are borderless (and therefore static, but you can move them again by using this code), transparent and below all other windows? You may have to poll each window under the rest every 100ms or so incase the user accidentally clicks it. I have made a little test with just some labels and it looks fine.
For example, use this code and poll the "below all other windows" method every so often.
<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LearnWPF.BorderlessWindow" Height="200" Width="200"
WindowStyle="None" ResizeMode="NoResize" AllowsTransparency="True"
Background="Transparent"
>
<Border Padding="5" BorderBrush="#feca00"
BorderThickness="3" Width="150" Height="150">
<TextBlock>Learn WPF!</TextBlock>
</Border>
</Window>