126 lines
3.7 KiB
C#
126 lines
3.7 KiB
C#
using Demo.Common.Models;
|
||
using Meeting.V2.Demo.ViewModels;
|
||
using Prism.Events;
|
||
using System;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
|
||
namespace Meeting.V2.Demo.Views
|
||
{
|
||
/// <summary>
|
||
/// VideoView.xaml 的交互逻辑
|
||
/// </summary>
|
||
public partial class VideoView : UserControl
|
||
{
|
||
|
||
|
||
public VideoView()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
|
||
public User UserInfo
|
||
{
|
||
get { return (User)GetValue(UserInfoProperty); }
|
||
set { SetValue(UserInfoProperty, value); }
|
||
}
|
||
|
||
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
|
||
public static readonly DependencyProperty UserInfoProperty =
|
||
DependencyProperty.Register("UserInfo", typeof(User), typeof(VideoView), new PropertyMetadata(null, new(OnUserInfoPropertyChangedCallback)));
|
||
|
||
private static void OnUserInfoPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||
{
|
||
if (d is VideoView videoView )
|
||
{
|
||
var viewDataContext = videoView.DataContext as VideoViewModel;
|
||
viewDataContext.UserInfo = e.NewValue as User;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#region 控制右上角操作按钮显示与消失
|
||
/// <summary>
|
||
/// 控制操作按钮显示
|
||
/// </summary>
|
||
private bool IsOperVisible = false;
|
||
|
||
private void pic_frame_MouseEnter(object sender, EventArgs e)
|
||
{
|
||
btn_oper.Visibility = Visibility.Visible;
|
||
}
|
||
|
||
private async void pic_frame_MouseLeave(object sender, EventArgs e)
|
||
{
|
||
|
||
// 使用ConfigureAwait(false)可以避免不必要的线程上下文切换
|
||
await Task.Delay(50).ConfigureAwait(false);
|
||
|
||
// 如果需要操作UI,使用Dispatcher
|
||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||
{
|
||
// UI相关操作
|
||
if (!IsOperVisible)
|
||
{
|
||
btn_oper.Visibility = Visibility.Hidden;
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private void btn_oper_MouseEnter(object sender, MouseEventArgs e)
|
||
{
|
||
IsOperVisible = true;
|
||
}
|
||
|
||
private async void btn_oper_MouseLeave(object sender, MouseEventArgs e)
|
||
{
|
||
await Task.Delay(50).ConfigureAwait(false);
|
||
|
||
|
||
IsOperVisible = false;
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#region 命令绑定
|
||
private void ExcuteCommand()
|
||
{
|
||
// 点击操作按钮,触发命令
|
||
Command?.Execute(CommandParameter);
|
||
}
|
||
|
||
// 依赖属性定义
|
||
public ICommand Command
|
||
{
|
||
get { return (ICommand)GetValue(CommandProperty); }
|
||
set { SetValue(CommandProperty, value); }
|
||
}
|
||
|
||
public static readonly DependencyProperty CommandProperty =
|
||
DependencyProperty.Register("Command", typeof(ICommand), typeof(VideoView), new PropertyMetadata(null));
|
||
|
||
public object CommandParameter
|
||
{
|
||
get { return GetValue(CommandParameterProperty); }
|
||
set { SetValue(CommandParameterProperty, value); }
|
||
}
|
||
|
||
public static readonly DependencyProperty CommandParameterProperty =
|
||
DependencyProperty.Register("CommandParameter", typeof(object), typeof(VideoView), new PropertyMetadata(null));
|
||
|
||
private void pic_frame_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
|
||
{
|
||
ExcuteCommand();
|
||
}
|
||
#endregion
|
||
|
||
|
||
}
|
||
}
|