|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Helper;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
-
- namespace BPASmartClient.CustomResource.Pages.View
- {
- /// <summary>
- /// LoginView.xaml 的交互逻辑
- /// </summary>
- public partial class LoginView : Window
- {
- public LoginView()
- {
- InitializeComponent();
- grid.Visibility = Visibility.Collapsed;
-
- Username.SelectionStart = Username.Text.Trim().Length;
- this.Loaded += LoginView_Loaded;
- ActionManage.GetInstance.Register(new Action(() =>
- {
- if (this.IsVisible)
- {
- this.DialogResult = true;
- this.Close();
- }
- }), "LoginOk", true);
- ActionManage.GetInstance.Register(new Action(() => { this.DialogResult = false; this.Close(); }), "ExitAction", true);
- }
-
- private void LoginView_Loaded(object sender, RoutedEventArgs e)
- {
- string path = $"{AppDomain.CurrentDomain.BaseDirectory}Videos\\Login.mp4";
- if (File.Exists(path))
- {
- player.Source = new Uri(path); // 绑定视频文件
- this.WindowState = WindowState.Maximized;
- player.LoadedBehavior = MediaState.Manual; // 交互式控制
- player.Loaded += new RoutedEventHandler(media_Loaded); // 添加元素加载完成事件 -- 自动开始播放
- player.MediaEnded += new RoutedEventHandler(media_MediaEnded); // 添加媒体播放结束事件 -- 重新播放
- player.Unloaded += new RoutedEventHandler(media_Unloaded);// 添加元素卸载完成事件 -- 停止播放
- player.MediaOpened += Player_MediaOpened;//已播放事件
- }
- }
-
- private void Player_MediaOpened(object sender, RoutedEventArgs e)
- {
- grid.Visibility = Visibility.Visible;
- Username.Focus();
- }
-
- private void media_Loaded(object sender, RoutedEventArgs e)
- {
- (sender as MediaElement).Play();
- }
-
- private void media_MediaEnded(object sender, RoutedEventArgs e)
- {
- // MediaElement需要先停止播放才能再开始播放,
- // 否则会停在最后一帧不动
- (sender as MediaElement).Stop();
- (sender as MediaElement).Play();
- }
-
- private void media_Unloaded(object sender, RoutedEventArgs e)
- {
- (sender as MediaElement).Stop();
- }
-
- private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
- {
- this.markText.Visibility = this.pb.Password.Length > 0 ? Visibility.Collapsed : Visibility.Visible;
- }
-
- private void TextBox_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Enter) pb.Focus();
- }
-
- private void pb_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Enter) ActionManage.GetInstance.Send("EnterLogin");
- }
- }
- }
|