XFEstudio/MyFirstRespo
完善窗口弹出功能
9194f98
代码差异
6 个文件
+108
-43
@@ -9,42 +9,74 @@ namespace XFEToolBox.Utilities;
9
9
10
10
public static class PopupHelper
11
11
{
12
public static NormalDialogPopupPage CreateNormalDialogPage(object content, PopupWindow popupWindow)
12
private static NormalDialogPopupPage CreateNormalDialogPage(object content)
13
13
{
14
var dialogPage = new NormalDialogPopupPage(popupWindow);
14
var dialogPage = new NormalDialogPopupPage();
15
15
dialogPage.ViewModel.Content = content;
16
16
return dialogPage;
17
17
}
18
18
19
public static MessageBoxResult? ShowNormalDialog(string text, Color textColor)
19
private static ScrollViewer CreateTextContent(string text, Color textColor) => new ScrollViewer()
20
20
{
21
var popupWindow = new PopupWindow();
22
var dialogPage = CreateNormalDialogPage(new ScrollViewer()
21
Content = new TextBlock
22
{
23
Text = text,
24
Foreground = new SolidColorBrush(textColor),
25
Margin = new Thickness(20, 20, 20, 0)
26
},
27
HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
28
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
29
Resources = new ResourceDictionary
23
30
{
24
Content = new TextBlock
25
{
26
Text = text,
27
Foreground = new SolidColorBrush(textColor),
28
Margin = new Thickness(20, 20, 20, 0)
29
},
30
HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
31
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
32
Resources = new ResourceDictionary
33
31
{
32
"scroll",
33
new Style
34
34
{
35
"scroll",
36
new Style
37
{
38
TargetType = typeof(ScrollBar),
39
BasedOn = (Style)Application.Current.FindResource("ConsoleScrollBar")
40
}
35
TargetType = typeof(ScrollBar),
36
BasedOn = (Style)Application.Current.FindResource("ConsoleScrollBar")
41
37
}
42
38
}
43
}, popupWindow);
44
popupWindow.ViewModel.Content = dialogPage;
39
}
40
};
41
42
public static MessageBoxResult? ShowConfirmDialog(object content, bool showCancelButton = false, string confirmText = "确定", string cancelText = "取消")
43
{
44
var dialog = CreateNormalDialogPage(content);
45
dialog.ViewModel.ConfirmText = confirmText;
46
dialog.ViewModel.CancelText = cancelText;
47
dialog.ViewModel.ConfirmGridLength = new GridLength(1, GridUnitType.Star);
48
if (showCancelButton)
49
dialog.ViewModel.CancelGridLength = new GridLength(1, GridUnitType.Star);
50
return ShowDialog(dialog);
51
}
52
53
public static MessageBoxResult? ShowConfirmDialog(string text, Color textColor, bool showCancelButton = false, string confirmText = "确定", string cancelText = "取消") => ShowConfirmDialog(CreateTextContent(text, textColor), showCancelButton, confirmText, cancelText);
54
55
public static MessageBoxResult? ShowConfirmDialog(string text, bool showCancelButton = false, string confirmText = "确定", string cancelText = "取消") => ShowConfirmDialog(text, Colors.Black, showCancelButton, confirmText, cancelText);
56
57
public static MessageBoxResult? ShowYesOrNoDialog(object content, bool showCancelButton = false, string yesText = "是", string noText = "否")
58
{
59
var dialog = CreateNormalDialogPage(content);
60
dialog.ViewModel.YesText = yesText;
61
dialog.ViewModel.NoText = noText;
62
dialog.ViewModel.YesGridLength = new GridLength(1, GridUnitType.Star);
63
dialog.ViewModel.NoGridLength = new GridLength(1, GridUnitType.Star);
64
if (showCancelButton)
65
dialog.ViewModel.CancelGridLength = new GridLength(1, GridUnitType.Star);
66
return ShowDialog(dialog);
67
}
68
69
public static MessageBoxResult? ShowYesOrNoDialog(string text, Color textColor, bool showCancelButton = false, string yesText = "是", string noText = "否") => ShowYesOrNoDialog(CreateTextContent(text, textColor), showCancelButton, yesText, noText);
70
71
public static MessageBoxResult? ShowYesOrNoDialog(string text, bool showCancelButton = false, string yesText = "是", string noText = "否") => ShowYesOrNoDialog(text, Colors.Black, showCancelButton, yesText, noText);
72
73
public static MessageBoxResult? ShowDialog(object content)
74
{
75
var popupWindow = new PopupWindow();
76
popupWindow.ViewModel.Content = content;
77
if (content is NormalDialogPopupPage normalDialogPopupPage)
78
normalDialogPopupPage.PopupWindow = popupWindow;
45
79
popupWindow.ShowDialog();
46
80
return popupWindow.Result;
47
81
}
48
49
public static MessageBoxResult? ShowNormalDialog(string text) => ShowNormalDialog(text, Colors.Black);
50
82
}
@@ -1,7 +1,6 @@
1
1
using CommunityToolkit.Mvvm.ComponentModel;
2
2
using CommunityToolkit.Mvvm.Input;
3
3
using System.Windows;
4
using XFEExtension.NetCore.TaskExtension;
5
4
using XFEToolBox.Views.Pages.Popups;
6
5
7
6
namespace XFEToolBox.ViewModel.Pages.Popups;
@@ -9,22 +8,56 @@ namespace XFEToolBox.ViewModel.Pages.Popups;
9
8
public partial class NormalDialogPopupPageViewModel(NormalDialogPopupPage viewPage) : ObservableObject
10
9
{
11
10
[ObservableProperty]
12
string confirmText = "确认";
11
string confirmText = "确定";
12
[ObservableProperty]
13
string yesText = "是";
14
[ObservableProperty]
15
string noText = "否";
13
16
[ObservableProperty]
14
17
string cancelText = "取消";
15
18
[ObservableProperty]
19
GridLength confirmGridLength = new(0);
20
[ObservableProperty]
21
GridLength yesGridLength = new(0);
22
[ObservableProperty]
23
GridLength noGridLength = new(0);
24
[ObservableProperty]
25
GridLength cancelGridLength = new(0);
26
[ObservableProperty]
16
27
object? content;
17
28
public NormalDialogPopupPage ViewPage { get; set; } = viewPage;
18
29
[RelayCommand]
19
30
void Confirm()
20
31
{
32
if (ViewPage.PopupWindow is null)
33
throw new InvalidOperationException("无法找到父窗口,未在用户返回前设置PopupWindow");
21
34
ViewPage.PopupWindow.Result = MessageBoxResult.OK;
22
35
ViewPage.PopupWindow.Close();
23
36
}
24
37
38
[RelayCommand]
39
void Yes()
40
{
41
if (ViewPage.PopupWindow is null)
42
throw new InvalidOperationException("无法找到父窗口,未在用户返回前设置PopupWindow");
43
ViewPage.PopupWindow.Result = MessageBoxResult.Yes;
44
ViewPage.PopupWindow.Close();
45
}
46
47
[RelayCommand]
48
void No()
49
{
50
if (ViewPage.PopupWindow is null)
51
throw new InvalidOperationException("无法找到父窗口,未在用户返回前设置PopupWindow");
52
ViewPage.PopupWindow.Result = MessageBoxResult.No;
53
ViewPage.PopupWindow.Close();
54
}
55
25
56
[RelayCommand]
26
57
void Cancel()
27
58
{
59
if (ViewPage.PopupWindow is null)
60
throw new InvalidOperationException("无法找到父窗口,未在用户返回前设置PopupWindow");
28
61
ViewPage.PopupWindow.Result = MessageBoxResult.Cancel;
29
62
ViewPage.PopupWindow.Close();
30
63
}
@@ -1,6 +1,4 @@
1
using System.Diagnostics;
2
using System.Windows.Controls;
3
using XFEToolBox.Utilities;
1
using System.Windows.Controls;
4
2
using XFEToolBox.ViewModel.Pages;
5
3
6
4
namespace XFEToolBox.Views.Pages;
@@ -19,9 +17,4 @@ public partial class DownloadPage : Page
19
17
InitializeComponent();
20
18
//Steam链接:https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe
21
19
}
22
23
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
24
{
25
Debug.WriteLine(PopupHelper.ShowNormalDialog("测试文本"));
26
}
27
20
}
@@ -13,18 +13,26 @@
13
13
14
14
<Grid>
15
15
<Grid.ColumnDefinitions>
16
<ColumnDefinition Width="*"/>
17
<ColumnDefinition Width="*"/>
16
<ColumnDefinition Width="{Binding ConfirmGridLength}"/>
17
<ColumnDefinition Width="{Binding YesGridLength}"/>
18
<ColumnDefinition Width="{Binding NoGridLength}"/>
19
<ColumnDefinition Width="{Binding CancelGridLength}"/>
18
20
</Grid.ColumnDefinitions>
19
21
<Grid.RowDefinitions>
20
22
<RowDefinition Height="*"/>
21
23
<RowDefinition Height="Auto"/>
22
24
</Grid.RowDefinitions>
23
<Frame Grid.ColumnSpan="2" Content="{Binding Content}" NavigationUIVisibility="Hidden"/>
25
<Frame Grid.ColumnSpan="4" Content="{Binding Content}" NavigationUIVisibility="Hidden"/>
24
26
<ctr:RoundButton Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding ConfirmCommand}">
25
27
<TextBlock Text="{Binding ConfirmText}" Foreground="#9898e7" Margin="16,8"/>
26
28
</ctr:RoundButton>
27
<ctr:RoundButton Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding CancelCommand}">
29
<ctr:RoundButton Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding YesCommand}">
30
<TextBlock Text="{Binding YesText}" Foreground="#9898e7" Margin="16,8"/>
31
</ctr:RoundButton>
32
<ctr:RoundButton Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding NoCommand}">
33
<TextBlock Text="{Binding NoText}" Foreground="#9898e7" Margin="16,8"/>
34
</ctr:RoundButton>
35
<ctr:RoundButton Grid.Row="1" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding CancelCommand}">
28
36
<TextBlock Text="{Binding CancelText}" Foreground="#9898e7" Margin="16,8"/>
29
37
</ctr:RoundButton>
30
38
</Grid>
@@ -10,10 +10,9 @@ namespace XFEToolBox.Views.Pages.Popups;
10
10
public partial class NormalDialogPopupPage : Page
11
11
{
12
12
public NormalDialogPopupPageViewModel ViewModel { get; set; }
13
public PopupWindow PopupWindow { get; set; }
14
public NormalDialogPopupPage(PopupWindow popupWindow)
13
public PopupWindow? PopupWindow { get; set; }
14
public NormalDialogPopupPage()
15
15
{
16
PopupWindow = popupWindow;
17
16
DataContext = ViewModel = new(this);
18
17
InitializeComponent();
19
18
}
@@ -11,7 +11,7 @@
11
11
<Window.Effect>
12
12
<DropShadowEffect BlurRadius="8" ShadowDepth="3" Direction="-45"/>
13
13
</Window.Effect>
14
<Border CornerRadius="15" Background="{Binding PopupBackground}" BorderBrush="{Binding PopupBorder}" BorderThickness="{Binding PopupThickness}" Margin="10">
14
<Border CornerRadius="16" Background="{Binding PopupContentBackground}" BorderBrush="{Binding PopupBorder}" BorderThickness="{Binding PopupThickness}" Margin="10">
15
15
<Grid>
16
16
<Grid.ColumnDefinitions>
17
17
<ColumnDefinition Width="*"/>
@@ -21,12 +21,12 @@
21
21
<RowDefinition Height="25"/>
22
22
<RowDefinition Height="*"/>
23
23
</Grid.RowDefinitions>
24
<Border Grid.ColumnSpan="2" CornerRadius="15,15,0,0" Background="{Binding PopupBackground}"/>
24
25
<Border x:Name="dragTabBorder" CornerRadius="15,0,15,0" Style="{StaticResource TabBorderStyle}" MouseMove="DragTabBorder_MouseMove" Visibility="{Binding MoveButtonVisibility}">
25
26
<Image x:Name="dragTabImage" Source="/Resources/Image/tabline.png" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4"/>
26
27
</Border>
27
28
<Image x:Name="closeWindowImage" Style="{StaticResource HalfRotorImage}" Grid.Column="1" Source="/Resources/Image/close.png" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4" MouseLeftButtonUp="CloseWindowImage_MouseLeftButtonUp" Visibility="{Binding CloseButtonVisibility}"/>
28
29
<Frame Grid.Row="1" Grid.ColumnSpan="2" x:Name="contentFrame" Content="{Binding Content}" NavigationUIVisibility="Hidden" Background="{Binding PopupContentBackground}" Margin="0,0,0,15"/>
29
<Border Grid.Row="1" Grid.ColumnSpan="2" CornerRadius="0,0,15,15" Background="{Binding PopupContentBackground}" Height="15" VerticalAlignment="Bottom"/>
30
30
</Grid>
31
31
</Border>
32
32
</Window>