自定义对话框 window 棱镜

Customize Dialog window prism

我已经实现了本期中所示的新 DialogService A New IDialogService for WPF

但是,这并没有说明如何编辑对话框本身的 window,因为 NotificationDialogUserControl

我尝试将其更改为 Window,但随后由于不是根 Window.

而引发异常

知道如何更改对话框的 Window 吗?

由于标题和图标设置在DialogViewModelBase,我也尝试添加ResizeMode 属性。

DialogViewModelBase中:

private ResizeMode _resizeMode;
public ResizeMode ResizeMode
{
   get => _resizeMode;
   set => SetProperty(ref _resizeMode, value);
}

并在 NotificationDialogViewModel 实施中:

public NotificationDialogViewModel()
{
    Title = "Notification";
    ResizeMode = System.Windows.ResizeMode.CanMinimize;
    CloseDialogCommand = new DelegateCommand(CloseDialog);
}

但是它没有按预期工作。

Any idea how can I change the Window of the dialog?

查看 code,看来您必须实施 IDialogWindow 并将默认注册覆盖到 built-in 实施。

此外,您无需继承DialogViewModelBase,只需实现IDialogAware即可。

对于搜索此内容的其他人 - 可以使用 prism:Dialog.WindowStyle.

设置样式

示例来自 https://github.com/PrismLibrary/Prism/blob/master/Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/NotificationDialog.xaml

新 link: 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>

也可以使用 Setter 设置其他属性。例如,

<Setter Property="WindowStyle" Value="None" />

将隐藏标题栏。