-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomRatioDialog.xaml.cs
More file actions
52 lines (45 loc) · 1.42 KB
/
CustomRatioDialog.xaml.cs
File metadata and controls
52 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Windows;
namespace ScreenGrid
{
public partial class CustomRatioDialog : Window
{
public List<int> ResultRatios { get; private set; } = new();
public string ResultName { get; private set; } = string.Empty;
public CustomRatioDialog()
{
InitializeComponent();
TxtRatios.Text = "1:1";
TxtName.Text = "Custom";
}
private void OnAdd(object sender, RoutedEventArgs e)
{
var parts = TxtRatios.Text
.Replace(",", ":")
.Replace(" ", "")
.Split(':', StringSplitOptions.RemoveEmptyEntries);
var parsed = new List<int>();
foreach (var p in parts)
{
if (int.TryParse(p, out int v) && v > 0)
parsed.Add(v);
}
if (parsed.Count == 0)
{
MessageBox.Show("Enter at least one positive number.\nExample: 2:1 or 3:2:1",
"Invalid", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
ResultRatios = parsed;
ResultName = TxtName.Text.Trim();
DialogResult = true;
Close();
}
private void OnCancel(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
}
}