I'm using MahApps.Metro UI for my WPF application. It's a good one and satisfies my needs, but I'd be more happy if somebody told me how to disable windows animation when they pop up.
When I call the Show() method, the new window pops up and I see an annoying animation (the content slides from right to left). The effect is similar to another one shown on the picture below (but it shows tabs and content goes left-to-right):
Sample of a dummy form please see below:
<controls:MetroWindow x:Class="TestProj.Views.TestView"
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"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:vm="clr-namespace:TestProj.ViewsModels"
Height="230" Width="550">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
</Grid>
</controls:MetroWindow>
Set WindowTransitionsEnabled="False" in xaml of the window.
As discussed on the equivalent GitHUb issue, the MetroWindow control template by default will use a MetroContentControl (which has this animation).
You need to edit the template to change it back to a ContentControl.
Sample code here
Related
I really like the solution from GazTheDestroyer to open a new window in MVVM WPF. My problem is that the window I want to show is a window and windows are not allowed in styles.
I have the following lines in my ResourceDictionary:
<DataTemplate DataType="{x:Type vm:ConfigViewModel}">
<vw:WinOptionsSimu />
</DataTemplate>
In WinOptionsSimu.xaml :
<Window x:Class="SimuDMSDMI.View.WinOptionsSimu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WinOptionsSimu" SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/SimuDMSDMI;component/Ressources/DictMainWindow.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
...
</Grid>
</Window>
After building the project, the line
is blue underlined and the tooltip shows "Can't put a Window in a style".
How can I solve this ?
Thanks in advance
I made a new CustomControl based on the Window Control.
When I use my Control it doesn't appear in the designer mode, instead it still uses the default window style.
How can I force the designer to display my window style instead of the default one?
My MainWindow.xaml:
<CustomWindow:MetroWindow x:Class="Testz.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CustomWindow="clr-namespace:MetroWindow;assembly=MetroWindow"
Title="MainWindow" Height="350" Width="525" BorderBrush="Red">
<Grid>
</Grid>
</CustomWindow:MetroWindow>
Link to my whole project - maybe you'll need it
How it looks in the designer and how it really looks:
I think I understood what you was trying to accomplish.
The problem is that the Visual Studio Designer can't find the Resource because it is on the library. What you need to do is to create a ResourceDictionary pointing to it on you Application to be able to see the designer time template.
<Application x:Class="DemoMetroWindow.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MetroWindow"
StartupUri="DemoWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:/MetroWindow;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
You can learn more from links bellow.
OnApplyTemplate() never being called
WPF get Type in Design time?
http://blogs.msdn.com/b/jgalasyn/archive/2007/10/29/troubleshooting-wpf-designer-load-failures.aspx
http://blogs.msdn.com/b/jnak/archive/2007/11/08/code-behind-and-the-wpf-designer.aspx
You're using Mahapps Metro, right?
You can use the styles provided by it.
Styling a window with Metro
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
You can change the color of the window by changing the Resource dictionary of Blue.xaml by other colors, just check it out.
When the resource references in App.xaml are fine you should restart Visual Studio. In most cases the themes are then displayed correctly.
Regards
I am new to WPF. I want to do something like this:
I have multiple dialogs in an application. I have created one theme with the required background, title bar and close button I want for all dialogs. Whereas, all dialogs size, and controls for them will differ.
For example: DialogWindow is a theme I have created for Window control.
On MainWindow (where I apply this DialogTheme), I can see this theme.
But when I try to add controls on it, they do not show up on the theme.
<Window x:Class="Example.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="391" Width="616"
Style="{DynamicResource DialogWindow}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/DialogsTheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
</Window>
I am not sure, what is going wrong. Any help will be appreciated.
You need to add these lines to each window you create to get achieve the style...
<Window...Style="{DynamicResource DialogWindow}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/DialogsTheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Finally got an answer, ContentPresenter is a thing required, which works as client area for window theme.
<ContentPresenter Grid.Row="1" Grid.ColumnSpan="2" x:Name="ClientArea" />
I have a WPF application I am developing, that allows the user to switch the current theme. I figured out how to switch themes... but it appears that the background of the application isn't affected by the theme:
(I blended three pictures together to conserve space)
How can I fix this? It clearly shows here that the background is supposed to change...
Here's the code I'm using:
MainWindow.xaml:
<Window x:Class="GDE.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" MinWidth="525" MinHeight="350">
<Grid>
....
</Grid>
</Window>
App.xaml:
<Application x:Class="GDE.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="ThemeDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/ExpressionDark.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
The themes define a background but you need to set it up yourself since it is not being referenced anywhere within the theme:
Background="{DynamicResource WindowBackgroundBrush}"
Why? I'd assume because styles are not automatically applied to derived classes, so if a style with theTargetType Window is set up that would also need to be set explicity since normally you use a subclass of Window, e.g. MainWindow.
My guess is that that the background we see in your screenshot does not belong to one of the themes, and this is the problem, you override theming when setting stuff manually.
lets assume we have the following control definition
<ctrl:ChildWindow x:Class="Control.Editor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ctrl="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:local="clr-namespace:Control"
Width="400" Height="300"
local:AttachedProperties.DialogResult="{Binding Path=DialogResult}"
Title="{Binding Path=Caption}" Style="{StaticResource Title}" DataContext="{Binding}" HasCloseButton="False">
<ctrl:ChildWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Control;component/Resources/BaseAppearance.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ctrl:ChildWindow.Resources>
</ctrl:ChildWindow>
The problem is that the style on the root control cannot be set because the ResourceDictionary is not loaded.
How can I get access to the StaticResource Title during the initialization of the control, when I don't have access to the App class? I'm also not sure that it would be possible, if I would have access to it.
Regards
I'd recommend accessing your resource and doing the work in the .Loaded() event of your control.
Edit: On second thought... I think I know what you're doing now... You have a resource set in your App.xaml class, but you want to access it in your control.
Easy way around the problem is to set it to a DynamicResource instead... but this is less performant.
What is the BuildAction set to on your App.xaml in the property's tab?
If it is ApplicationDefinition... then you should be able to access your resource as you currently are.
I found the common way without using code behind. I knew it is possible. ^^
<ctrl:ChildWindow x:Class="Control.Editor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ctrl="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:local="clr-namespace:Control"
Width="400" Height="300"
local:AttachedProperties.DialogResult="{Binding Path=DialogResult}"
Title="{Binding Path=Caption}" DataContext="{Binding}" HasCloseButton="False">
<ctrl:ChildWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Control;component/Resources/BaseAppearance.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ctrl:ChildWindow.Resources>
<crtl:ChildWindow.Style>
<StaticResource ResourceKey="Title" />
</crtl:ChildWindow.Style>
</ctrl:ChildWindow>