ghost1372 / HandyControls

Contains some simple and commonly used WPF controls based on HandyControl
https://ghost1372.github.io/
MIT License
1.07k stars 102 forks source link

using <prism:Dialog.WindowStyle> to change properties of hc:Window/GlowWindow causes window titlebar to disappear #177

Closed DineshSolanki closed 1 year ago

DineshSolanki commented 1 year ago

Describe the bug

I'm trying to show window/GlowWindow as PrismDialog parent in WPF, I followed this https://prismlibrary.com/docs/wpf/dialog-service.html#register-a-custom-dialog-window guide, and was able to make dialogService use hc:Window image

however when I try to set window width, height or any property using (https://prismlibrary.com/docs/wpf/dialog-service.html#register-a-custom-dialog-window)

<prism:Dialog.WindowStyle>
    <Style TargetType="Window">
        <Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
    </Style>
</prism:Dialog.WindowStyle>

the titlebar disappears from window

image

this works with normal window, but not with hc:window/glowWindow

Steps to reproduce the bug

  1. Setup "Prism.DryIoc" in an WPF app.
  2. Create a userControl
    <Border x:Class="HandyControlDemo.UserControl.TextDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:hc="https://handyorg.github.io/handycontrol"
        prism:ViewModelLocator.AutoWireViewModel="True"
        CornerRadius="10"
        Width="400"
        Height="247"
        Background="{DynamicResource RegionBrush}">
    <hc:SimplePanel>
        <TextBlock Style="{StaticResource TextBlockLargeBold}" Text="Please Wait"/>
        <Button Width="22" Height="22" Command="hc:ControlCommands.Close" Style="{StaticResource ButtonIcon}" Foreground="{DynamicResource PrimaryBrush}" hc:IconElement.Geometry="{StaticResource ErrorGeometry}" Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,4,0"/>    
    </hc:SimplePanel>
    </Border>
  3. Create a class to register hc:window with prism dialog service

    public partial class HandyWindow : HandyControl.Controls.Window, IDialogWindow
    {
        public IDialogResult Result { get; set; }
    
        public HandyWindow()
        {
        }
    }
  4. Register the HandyWindow and created userControl in app.xaml.cs
    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterDialog<MyUserControl, MyUserControlViewModel>("MyUserControl");
        containerRegistry.RegisterDialogWindow<HandyWindow>();
    }
  5. try showing 'MyUserControl' with prism dialog service
    dialogService.ShowDialog("MyUserControl",  _ => { });
  6. the user control will show correctly as a dialog.
  7. now try changing the width or any property of dialog parent using in usercontrol
    <Border x:Class="HandyControlDemo.UserControl.TextDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:hc="https://handyorg.github.io/handycontrol"
        prism:ViewModelLocator.AutoWireViewModel="True"
        CornerRadius="10"
        Width="400"
        Height="247"
        Background="{DynamicResource RegionBrush}">
    <prism:Dialog.WindowStyle>
        <Style TargetType="hc:Window">
            <Setter Property="Height" Value="500" />
            <Setter Property="Width" Value="636" />
        </Style>
    </prism:Dialog.WindowStyle>
    <hc:SimplePanel>
        <TextBlock Style="{StaticResource TextBlockLargeBold}" Text="Please Wait"/>
        <Button Width="22" Height="22" Command="hc:ControlCommands.Close" Style="{StaticResource ButtonIcon}" Foreground="{DynamicResource PrimaryBrush}" hc:IconElement.Geometry="{StaticResource ErrorGeometry}" Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,4,0"/>    
    </hc:SimplePanel>
    </Border>
  8. try showing the usercontrol again
    dialogService.ShowDialog("MyUserControl",  _ => { });
  9. The title bar now doesn't display

Expected behavior

The title bar should have displayed as is the case with normal window

Screenshots

with

 <prism:Dialog.WindowStyle>
        <Style TargetType="hc:Window">
            <Setter Property="Icon" Value="/Resources/folicon Icon.ico"/>
            <Setter Property="Height" Value="500" />
            <Setter Property="Width" Value="636" />
            <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
            <Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterOwner" />
        </Style>
    </prism:Dialog.WindowStyle>

image

without it image

NuGet package version

None

IDE

Visual Studio 2022

Framework type

.Net 5.0

Windows version

Windows 11 (22000)

Additional context

No response

ghost1372 commented 1 year ago

report in original repo

DineshSolanki commented 1 year ago

for anyone else stumbling on this, you can fix #117 it by creating a custom window that extends HandyControl.Controls.Window and explicitly maps the default style key property to HandyControl.Controls.Window. Here's how the updated HandyWindow class looks:

namespace FoliCon.Modules;

public class HandyWindow : HandyControl.Controls.Window, IDialogWindow
{
    static HandyWindow()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(HandyWindow),
            new FrameworkPropertyMetadata(typeof(HandyControl.Controls.Window)));
    }

    public HandyWindow()
    {
        ShowTitle = true;
        InitializeProperties();
        Background = (System.Windows.Media.Brush)FindResource("RegionBrush");
    }

    public IDialogResult Result { get; set; }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        InitializeProperties();
    }

    private void InitializeProperties()
    {
        if (DataContext is IDialogAware dialogAware)
        {
            Title = dialogAware.Title;
        }
    }
}