我已经实现了新的 DialogService,如本期 A New IDialogService for WPF 所示
但是,这并没有解释如何编辑对话框本身的窗口,因为它NotificationDialog是一个UserControl.
我曾尝试将其更改为 aWindow但由于不是根窗口而引发异常。
知道如何更改对话框的窗口吗?
由于标题和图标设置在 中DialogViewModelBase,我也尝试添加一个ResizeMode属性。
在DialogViewModelBase:
private ResizeMode _resizeMode;
public ResizeMode ResizeMode
{
get => _resizeMode;
set => SetProperty(ref _resizeMode, value);
}
Run Code Online (Sandbox Code Playgroud)
并在NotificationDialogViewModel实施中:
public NotificationDialogViewModel()
{
Title = "Notification";
ResizeMode = System.Windows.ResizeMode.CanMinimize;
CloseDialogCommand = new DelegateCommand(CloseDialog);
}
Run Code Online (Sandbox Code Playgroud)
但是,它不能按预期工作。
对于搜索此内容的其他人 - 可以使用prism:Dialog.WindowStyle.
来自https://github.com/PrismLibrary/Prism/blob/master/Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/NotificationDialog.xaml 的示例
新链接:https : //prismlibrary.com/docs/wpf/dialog-service.html#style-the-dialogwindow
<UserControl x:Class="HelloWorld.Dialogs.NotificationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Width="300" Height="150">
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="ShowInTaskbar" Value="False"/>
<Setter Property="SizeToContent" Value="WidthAndHeight"/>
</Style>
</prism:Dialog.WindowStyle>
<Grid x:Name="LayoutRoot" Margin="5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding Message}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" TextWrapping="Wrap" />
<Button Command="{Binding CloseDialogCommand}" CommandParameter="True" Content="OK" Width="75" Height="25" HorizontalAlignment="Right" Margin="0,10,0,0" Grid.Row="1" IsDefault="True" />
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
也可以使用 设置其他属性Setter。例如,
<Setter Property="WindowStyle" Value="None" />
Run Code Online (Sandbox Code Playgroud)
将隐藏标题栏。