Reputation: 656
I have implemented the new DialogService as shown in this issue A New IDialogService for WPF
However, this doesn't explain how to edit the window of the dialog itself, since the NotificationDialog
is a UserControl
.
I have tried changing it to a Window
but then an exception is raised due to not being the root Window.
Any idea how can I change the Window of the dialog?
Since the Title and the Icon is set in DialogViewModelBase
, I have tried to add a ResizeMode
property as well.
In DialogViewModelBase
:
private ResizeMode _resizeMode;
public ResizeMode ResizeMode
{
get => _resizeMode;
set => SetProperty(ref _resizeMode, value);
}
and in NotificationDialogViewModel
implementation:
public NotificationDialogViewModel()
{
Title = "Notification";
ResizeMode = System.Windows.ResizeMode.CanMinimize;
CloseDialogCommand = new DelegateCommand(CloseDialog);
}
However it doesn't work as intended.
Upvotes: 3
Views: 6800
Reputation: 765
For others who search for this - the style can be set using prism:Dialog.WindowStyle
.
Example from
https://github.com/PrismLibrary/Prism/blob/master/Sandbox/Wpf/HelloWorld/HelloWorld/Dialogs/NotificationDialog.xaml
New 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>
Other properties can also be set using Setter
. For example,
<Setter Property="WindowStyle" Value="None" />
will hide the title bar.
Upvotes: 11
Reputation: 10863
Any idea how can I change the Window of the dialog?
Looking at the code, it looks like you have to implement IDialogWindow
and override the default registration to the built-in implementation.
Also, you don't need to inherit from DialogViewModelBase
, just implementing IDialogAware
suffices.
Upvotes: 1