mui
mui copied to clipboard
how to hide close button in ModernWindow
To Develop Windows Application By Modern UI for WPF then I need to hide to close button ?
I think you'll need to change the window template, there's nothing native for that
I have similar issue. In my case, i create new calss CmuDialog for dialog .
using System.Windows;
namespace Marcorp.Charon.Modernui.Base.Class
{
public class CmuDialog : FirstFloor.ModernUI.Windows.Controls.DpiAwareWindow, Windows.Controls.IClosableDialog
{
#region Właściwości wykorzystywane do dynamicznego budowania szablony XAML
/// <summary>
/// Zależność BackgroundContent.
/// </summary>
public static readonly DependencyProperty BackgroundContentProperty = DependencyProperty.Register("BackgroundContent", typeof(object), typeof(CmuDialog));
/// <summary>
/// Zależność BorderColorProperty.
/// </summary>
public static readonly DependencyProperty AccentColorProperty = DependencyProperty.Register("AccentColor", typeof(System.Windows.Media.Color), typeof(CmuDialog));
/// <summary>
/// Zależność ActiveBorderProperty.
/// </summary>
public static readonly DependencyProperty AccentColorActiveProperty = DependencyProperty.Register("AccentColorActive", typeof(System.Windows.Media.Color), typeof(CmuDialog));
/// <summary>
/// Gets or sets: background content of this window instance.
/// </summary>
public object BackgroundContent
{
get { return GetValue(BackgroundContentProperty); }
set { SetValue(BackgroundContentProperty, value); }
}
/// <summary>
/// Get or sets: Kolo akcentu nieaktywnego okna
/// </summary>
public System.Windows.Media.Color AccentColor
{
get { return (System.Windows.Media.Color)GetValue(AccentColorProperty); }
set { SetValue(AccentColorProperty, value); }
}
/// <summary>
/// Get or sets: Kolor akcentu gdy okno jest aktywne
/// </summary>
public System.Windows.Media.Color AccentColorActive
{
get { return (System.Windows.Media.Color)GetValue(AccentColorActiveProperty); }
set { SetValue(AccentColorActiveProperty, value); }
}
/// <summary>
/// Zależność IsSystemCloseButtonEnabled określająca czy ma być aktywny przycisk X na belce
/// </summary>
public static readonly DependencyProperty IsSystemCloseButtonEnabledProperty = DependencyProperty.Register("IsSystemCloseButtonEnabled", typeof(bool), typeof(CmuDialog));
/// <summary>
/// Gets or sets: Czy ma być aktywny przycisk X na belce
/// </summary>
public bool IsSystemCloseButtonEnabled
{
get { return (bool)GetValue(IsSystemCloseButtonEnabledProperty); }
set { SetValue(IsSystemCloseButtonEnabledProperty, value); }
}
#endregion
/// <summary>
/// Konstruktor domyślny
/// </summary>
public CmuDialog()
: base()
{
#if NET45
this.CommandBindings.Add(new System.Windows.Input.CommandBinding(SystemCommands.CloseWindowCommand, OnCloseWindow));
#else
CommandBindings.Add(new System.Windows.Input.CommandBinding(Microsoft.Windows.Shell.SystemCommands.CloseWindowCommand, OnCloseWindow));
#endif
//ustawienie domyślnych wartości
IsSystemCloseButtonEnabled = true;
//ustawienie stylu okna
SetResourceReference(StyleProperty, typeof(CmuDialog));
// próba wyznaczenia rodzica okienka
if (Application.Current != null && Application.Current.MainWindow != this)
Owner = Application.Current.MainWindow;
//wycentrowanie okienka
WindowStartupLocation = Owner == null ?
WindowStartupLocation.CenterScreen :
WindowStartupLocation.CenterOwner;
}
/// <summary>
/// Przykrycie funkcji wyświetlającej niemodalne okno dialogowe
/// </summary>
private new void Show() { base.Show(); }
/// <summary>
/// Zamknięcie okna dialogowego
/// </summary>
/// <param name="target"></param>
/// <param name="e"></param>
protected virtual void OnCloseWindow(object target, RoutedEventArgs e)
{
#if NET45
SystemCommands.CloseWindow(this);
#else
Microsoft.Windows.Shell.SystemCommands.CloseWindow(this);
#endif
}
private System.Windows.Media.SolidColorBrush WindowBorder
{
get { return new System.Windows.Media.SolidColorBrush { Color = AccentColor, Opacity = 0.5 }; }
}
}
}
In this class i have property IsSystemCloseButtonEnabled, and dedicated styl
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cmu="clr-namespace:Marcorp.Charon.Modernui.Base.Class"
xmlns:mui="clr-namespace:FirstFloor.ModernUI.Windows.Controls;assembly=FirstFloor.ModernUI"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/Button.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/TextBox.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/Converters.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type cmu:CmuDialog}">
<!--<Style.Resources>
<SolidColorBrush x:Key="WindowBorder" Color="{Binding AccentColor}" Opacity=".5" />
<SolidColorBrush x:Key="WindowBorderActive" Color="{Binding AccentColorActive}" />
<LinearGradientBrush x:Key="WindowHeaderGradient" StartPoint="0, 0" EndPoint="0, 1" Opacity=".1">
<GradientStop Offset="0" Color="{Binding AccentColor}" />
<GradientStop Offset=".3" Color="{Binding AccentColor}" />
<GradientStop Offset="1" Color="Transparent" />
</LinearGradientBrush>
<Rectangle x:Key="WindowBackgroundContent" Height="96" Fill="{StaticResource WindowHeaderGradient}" VerticalAlignment="Top"/>
<LinearGradientBrush x:Key="WindowHeaderGradientActive" StartPoint="0, 0" EndPoint="0, 1" Opacity=".1">
<GradientStop Offset="0" Color="{Binding AccentColorActive}" />
<GradientStop Offset=".3" Color="{Binding AccentColorActive}" />
<GradientStop Offset="1" Color="Transparent" />
</LinearGradientBrush>
<Rectangle x:Key="WindowBackgroundContentActive" Height="96" Fill="{StaticResource WindowHeaderGradientActive}" VerticalAlignment="Top"/>
</Style.Resources>-->
<Setter Property="BackgroundContent" Value="{DynamicResource WindowBackgroundContent}" />
<Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}" />
<Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}" />
<Setter Property="Foreground" Value="{DynamicResource WindowText}" />
<Setter Property="AccentColor" Value="{DynamicResource AccentColor}" />
<Setter Property="AccentColorActive" Value="{DynamicResource AccentColor}" />
<Setter Property="ShowInTaskbar" Value="False" />
<Setter Property="ResizeMode" Value="NoResize" />
<Setter Property="SizeToContent" Value="WidthAndHeight" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
<Setter Property="Topmost" Value="True" />
<Setter Property="AllowsTransparency" Value="True" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cmu:CmuDialog}">
<Border CornerRadius="4">
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="1.2" Opacity="0.8" Color="{DynamicResource AccentColor}" RenderingBias="Quality" />
</Border.Effect>
<Border Background="{DynamicResource WindowBackground}" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
<Grid>
<Border BorderBrush="{DynamicResource WindowBorder}" BorderThickness="1">
<AdornerDecorator>
<Grid>
<!-- window background content -->
<ContentControl Content="{TemplateBinding BackgroundContent}" />
<!--<Rectangle Height="96" VerticalAlignment="Top">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0, 0" EndPoint="0, 1" Opacity=".1">
<GradientStop Offset="0" Color="{TemplateBinding AccentColor}" />
<GradientStop Offset=".3" Color="{TemplateBinding AccentColor}" />
<GradientStop Offset="1" Color="Transparent" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</ContentControl>-->
<!-- top blob -->
<Canvas>
<Rectangle Fill="{DynamicResource Accent}" Canvas.Top="18" Canvas.Left="24" Width="100" Height="6" />
</Canvas>
<!--Symulacja belki okna-->
<Grid Margin="0, 24, 0, 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- tytuł okienka -->
<StackPanel Margin="24, 20, 0, 0"
Grid.Column="0"
Grid.Row="0">
<TextBlock
DataContext="{TemplateBinding Title}"
Text="{Binding Converter={StaticResource ToUpperConverter}}"
FontFamily="Segoe UI"
FontSize="24"
TextOptions.TextFormattingMode="Ideal"
TextTrimming="CharacterEllipsis"/>
</StackPanel>
<!--Przycisk X na belce-->
<StackPanel Orientation="Horizontal"
Height="Auto"
HorizontalAlignment="Right"
Grid.Column="1"
Grid.Row="0"
VerticalAlignment="Top"
shell:WindowChrome.IsHitTestVisibleInChrome="True"
Margin="0">
<!--net 4.5 only-->
<Button Command="{Binding Source={x:Static shell:SystemCommands.CloseWindowCommand}}"
Style="{StaticResource SystemCloseButton}"
IsEnabled="{TemplateBinding IsSystemCloseButtonEnabled}"
Visibility="{TemplateBinding IsSystemCloseButtonEnabled, Converter={StaticResource BooleanToVisibilityConverter}}">
<Button.Content>
<Grid Width="13" Height="12" RenderTransform="1,0,0,1,0,1">
<Path Data="M0,0 L8,7 M8,0 L0,7 Z"
Width="8"
Height="7"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
StrokeThickness="1.5" />
</Grid>
</Button.Content>
</Button>
</StackPanel>
<mui:TransitioningContentControl Margin="15, 10"
Content="{TemplateBinding Content}"
Grid.Row="1"
Grid.ColumnSpan="2" />
</Grid>
</Grid>
</AdornerDecorator>
</Border>
<Border BorderBrush="{DynamicResource WindowBorderActive}" BorderThickness="1" Visibility="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type cmu:CmuDialog}}, Converter={StaticResource BooleanToVisibilityConverter}}" />
</Grid>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsActive" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource WindowBorderActive}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome CornerRadius="0" GlassFrameThickness="1" UseAeroCaptionButtons="False" />
</Setter.Value>
</Setter>
<!--<Style.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.8" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>-->
</Style>
</ResourceDictionary>