一.无放大缩小按钮 但是点击右上角可以关闭
搭建好Prism框架后开始对DialogWindow和Dialog的UserControl设置
- window设置
<WindowChrome GlassFrameThickness="-1"/>
当 GlassFrameThickness=“1” 时候点击右上角无响应
完整代码
<Window x:Class="XXDialogWindow.DialogWindowEx"
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:XXDialogWindow"
mc:Ignorable="d"
Title="DialogWindowEx" Height="450" Width="800">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="-1"/>
</WindowChrome.WindowChrome>
<Grid>
</Grid>
</Window>
二. 显示右上角窗口按钮
将DialogWindow 的窗体背景颜色Background设置为Transparent, 显示右上角的窗口按钮;将ResizeMode设置为NoMode,窗口按钮只保留退出x。
- Background=“Transparent”
<Window x:Class="XXDialogWindow.DialogWindowEx"
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:XXDialogWindow"
mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="200" Height="480" Width="500"
Title="DialogWindowEx" Background="Transparent" >
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="-1"/>
</WindowChrome.WindowChrome>
<Grid>
</Grid>
</Window>
```
2. ResizeMode="NoResize"
```csharp
<Window x:Class="XXDialogWindow.DialogWindowEx"
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:XXDialogWindow"
mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="200" Height="480" Width="500"
Title="DialogWindowEx" Background="Transparent" ResizeMode="NoResize">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="-1"/>
</WindowChrome.WindowChrome>
<Grid>
</Grid>
</Window>
二. 弹窗宽高自适应
目前已知有三种方式可以实现。
- 一种是DialogWindow的宽高做绑定
Width="{Binding Content.Width,RelativeSource={RelativeSource Self}}"
Height="{Binding Content.Height,RelativeSource={RelativeSource Self}}">
- DialogView采用prism style
<UserControl x:Class="XXDialogWindow.Views.TextView"
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:local="clr-namespace:XXDialogWindow.Views"
mc:Ignorable="d"
xmlns:p="http://prismlibrary.com/"
d:DesignHeight="400" d:DesignWidth="800" >
<p:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="Height" Value="300"/>
<Setter Property="Width" Value="300"/>
<Setter Property="p:Dialog.WindowStartupLocation" Value="CenterScreen" />
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="ShowInTaskbar" Value="False"/>
<!--<Setter Property="SizeToContent" Value="WidthAndHeight"/>-->
</Style>
</p:Dialog.WindowStyle>
<Grid>
<TextBlock Text="Text" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="22"/>
</Grid>
</UserControl>
Dialogwindow
<Window x:Class="XXDialogWindow.DialogWindowEx"
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:XXDialogWindow"
mc:Ignorable="d" Height="480" Width="500"
Title="DialogWindowEx" Background="Transparent" ResizeMode="NoResize">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="-1"/>
</WindowChrome.WindowChrome>
<Grid>
</Grid>
</Window>
- 将Dialogwindow 的SizeToContent属性设置为WidthAndHeight,并设置DialogView的宽高
Dialogwindow
<Window x:Class="XXDialogWindow.DialogWindowEx"
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:XXDialogWindow"
mc:Ignorable="d" Height="480" Width="500" SizeToContent="WidthAndHeight"
Title="DialogWindowEx" Background="Transparent" ResizeMode="NoResize">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="-1"/>
</WindowChrome.WindowChrome>
<Grid>
</Grid>
</Window>
DialogView
<UserControl x:Class="XXDialogWindow.Views.TextView"
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:local="clr-namespace:XXDialogWindow.Views"
mc:Ignorable="d"
xmlns:p="http://prismlibrary.com/"
d:DesignHeight="400" d:DesignWidth="800" Height="200" Width="100">
<p:Dialog.WindowStyle>
<Style TargetType="Window">
<!--<Setter Property="Height" Value="300"/>
<Setter Property="Width" Value="300"/>-->
<!--<Setter Property="p:Dialog.WindowStartupLocation" Value="CenterScreen" />
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="ShowInTaskbar" Value="False"/>-->
<!--<Setter Property="SizeToContent" Value="WidthAndHeight"/>-->
</Style>
</p:Dialog.WindowStyle>
<Grid>
<TextBlock Text="Text" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="22"/>
</Grid>
</UserControl>