更改window棱镜对话框的样式

时间:2019-09-20 09:04:33

标签: prism

如何通过触发器动态更改窗口样式? 喜欢:

<Style TargetType="UserControl">

    <Setter Property="prism:Dialog.WindowStyle" Value="{DynamicResource  DefaultDialogStyleTheme}"></Setter>
    <Style.Triggers>

        <DataTrigger
            Binding="{Binding SecondOne, UpdateSourceTrigger=PropertyChanged}"
            Value="true">                    
            <Setter Property="prism:Dialog.WindowStyle" Value="{DynamicResource DialogStyleTheme}"></Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>`

2 个答案:

答案 0 :(得分:0)

您可以注册自己的IDialogWindow实现,该实现具有所需的所有样式。

该库的实现的代码here (xaml)there (code-behind)作为参考。

答案 1 :(得分:0)

感谢您的帮助:),但是例如,在切换到新的Prism之前,我们已经使用PopupWindowAction引发默认窗口或自定义窗口:

  var wrapperWindow = GetWindow(args.Context);                                                                
  wrapperWindow.ShowDialog(); 

GetWindow返回一个Window或CustomWindowObject。

这是自定义窗口样式:

   <Style x:Key="DialogStyleTheme" TargetType="implementation:CustomDialogWindow">
    <Setter Property="WindowStyle" Value="None" />
    <Setter Property="ResizeMode" Value="CanMinimize" />
    <Setter Property="SizeToContent" Value="WidthAndHeight" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="AllowsTransparency" Value="True" />
    <Setter Property="FontSize" Value="60" />
    <Setter Property="ShowInTaskbar" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="implementation:CustomDialogWindow">
                <Border BorderThickness="2" CornerRadius="10" BorderBrush="White" Background="DimGray"
                        x:Name="MainBorder">
                    <Grid Background="{TemplateBinding Background}" Margin="5,5,5,5">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="30" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0" x:Name="MoveGrid">
                            <Image x:Name="Image">
                                <Image.Style>
                                    <Style TargetType="Image">
                                        <Setter Property="Stretch" Value="UniformToFill" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding SmallTitle}" Value="true">
                                                <Setter Property="Height" Value="40" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                            <TextBlock Text="{Binding Title}">
                                <TextBlock.Style>
                                    <Style BasedOn="{StaticResource TouchHeadTextBlock}" TargetType="TextBlock">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding SmallTitle}" Value="true">
                                                <Setter Property="FontSize" Value="25" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                        </Grid>
                        <ContentPresenter Grid.Row="2" x:Name="ContentPresenter" ClipToBounds="True" />
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我正在UserControl中设置WindowStyle,我想通过触发器更改此样式。...

 prism:Dialog.WindowStyle="{DynamicResource DialogStyleTheme}"

初始化:

    containerRegistry.RegisterDialog<ItemSelectionDialogView, ItemSelectionDialogViewModel>();
    containerRegistry.RegisterDialogWindow<CustomDialogWindow>();