-
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Window x:Class="BililiveRecorder.WPF.TimedMessageBox" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:BililiveRecorder.WPF" | ||
mc:Ignorable="d" ResizeMode="NoResize" | ||
Title="TimedMessageBox" Height="200" Width="320" | ||
Loaded="Window_Loaded"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="1*"/> | ||
<ColumnDefinition Width="1*"/> | ||
</Grid.ColumnDefinitions> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="5*"/> | ||
<RowDefinition Height="3*"/> | ||
</Grid.RowDefinitions> | ||
<TextBlock Grid.ColumnSpan="2" VerticalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" FontSize="16" Text="{Binding Message}"/> | ||
<Button Grid.Row="1" Grid.Column="0" Margin="10" FontSize="20" Click="ConfirmClick"> | ||
确定 | ||
</Button> | ||
<Button Grid.Row="1" Grid.Column="1" Margin="10" Click="CancelClick"> | ||
<TextBlock FontSize="20">取消 (<TextBlock Text="{Binding CountDown}"/>)</TextBlock> | ||
</Button> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using System.Windows; | ||
using System.Windows.Threading; | ||
|
||
namespace BililiveRecorder.WPF | ||
{ | ||
/// <summary> | ||
/// TimedMessageBox.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class TimedMessageBox : Window, INotifyPropertyChanged | ||
{ | ||
public string Message { get => _message; set => SetField(ref _message, value); } | ||
private string _message = string.Empty; | ||
|
||
public int CountDown { get => _countdown; set => SetField(ref _countdown, value); } | ||
private int _countdown = 10; | ||
|
||
private DispatcherTimer timer; | ||
|
||
public TimedMessageBox() | ||
{ | ||
timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1), IsEnabled = false }; | ||
timer.Tick += (sender, e) => | ||
{ | ||
CountDown -= 1; | ||
if (CountDown <= 0) | ||
{ | ||
Cancel(); | ||
timer.Stop(); | ||
timer = null; | ||
} | ||
}; | ||
|
||
DataContext = this; | ||
|
||
InitializeComponent(); | ||
} | ||
|
||
private void ConfirmClick(object sender, RoutedEventArgs e) | ||
{ | ||
DialogResult = true; | ||
Close(); | ||
} | ||
|
||
private void CancelClick(object sender, RoutedEventArgs e) => Cancel(); | ||
|
||
private void Cancel() | ||
{ | ||
DialogResult = false; | ||
Close(); | ||
} | ||
|
||
private void Window_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
timer?.Start(); | ||
} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = "") | ||
{ | ||
if (EqualityComparer<T>.Default.Equals(field, value)) { return false; } | ||
field = value; OnPropertyChanged(propertyName); return true; | ||
} | ||
} | ||
} |