@@ -8,6 +8,15 @@ namespace AutoMidiPlayer.WPF.ModernWPF;
88
99public class ImportDialog : ContentDialog
1010{
11+ static ImportDialog ( )
12+ {
13+ // Ensure the base ContentDialog style is applied to this derived dialog.
14+ DefaultStyleKeyProperty . OverrideMetadata (
15+ typeof ( ImportDialog ) ,
16+ new FrameworkPropertyMetadata ( typeof ( ContentDialog ) )
17+ ) ;
18+ }
19+
1120 private readonly Wpf . Ui . Controls . TextBox _titleBox ;
1221 private readonly Wpf . Ui . Controls . TextBox _authorBox ;
1322 private readonly Wpf . Ui . Controls . TextBox _albumBox ;
@@ -69,6 +78,40 @@ public uint SongMergeMilliseconds
6978
7079 public ImportDialog ( string defaultTitle , int defaultKey = 0 , Transpose defaultTranspose = Transpose . Ignore , string ? defaultAuthor = null , string ? defaultAlbum = null , DateTime ? defaultDateAdded = null , double nativeBpm = 120 , double ? customBpm = null , bool ? mergeNotes = null , uint ? mergeMilliseconds = null , bool ? holdNotes = null )
7180 {
81+ // Set up the DialogHost for this ContentDialog
82+ DialogHelper . SetupDialogHost ( this ) ;
83+
84+ if ( Application . Current . TryFindResource ( typeof ( ContentDialog ) ) is Style dialogStyle )
85+ {
86+ Style = dialogStyle ;
87+ }
88+
89+ // Keep the dialog within the active window bounds to avoid clipping on fullscreen toggle.
90+ var activeWindow = Application . Current . Windows . OfType < Window > ( ) . FirstOrDefault ( w => w . IsActive )
91+ ?? Application . Current . MainWindow ;
92+ if ( activeWindow != null )
93+ {
94+ void UpdateDialogBounds ( )
95+ {
96+ var maxHeight = Math . Max ( 0 , activeWindow . ActualHeight - 120 ) ;
97+ var maxWidth = Math . Max ( 0 , activeWindow . ActualWidth - 120 ) ;
98+ DialogMaxHeight = maxHeight ;
99+ DialogMaxWidth = maxWidth ;
100+ DialogMargin = new Thickness ( 24 ) ;
101+ }
102+
103+ UpdateDialogBounds ( ) ;
104+ SizeChangedEventHandler ? sizeChangedHandler = ( _ , _ ) => UpdateDialogBounds ( ) ;
105+ activeWindow . SizeChanged += sizeChangedHandler ;
106+ EventHandler ? stateChangedHandler = ( _ , _ ) => UpdateDialogBounds ( ) ;
107+ activeWindow . StateChanged += stateChangedHandler ;
108+ Closed += ( _ , _ ) =>
109+ {
110+ activeWindow . SizeChanged -= sizeChangedHandler ;
111+ activeWindow . StateChanged -= stateChangedHandler ;
112+ } ;
113+ }
114+
72115 Title = "Edit Song" ;
73116 PrimaryButtonText = "Save" ;
74117 CloseButtonText = "Cancel" ;
0 commit comments