wpf3d游戏引擎ControlTemplate.xaml.cs文件实现

ControlTemplate.xaml.cs

using System.Windows;

using System.Windows.Controls;

using System.Windows.Input;

namespace PrimalEditor.Dictionaries

{

public partial class ControlTemplates : ResourceDictionary

{

private void OnTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)

{

var textBox = sender as TextBox;

var exp = textBox.GetBindingExpression(TextBox.TextProperty);

if (exp == null) return;

if (e.Key == Key.Enter)

{

if (textBox.Tag is ICommand command && command.CanExecute(textBox.Text))

{

command.Execute(textBox.Text);

}

else

{

exp.UpdateSource();

}

Keyboard.ClearFocus();

e.Handled = true;

}

else if (e.Key == Key.Escape)

{

exp.UpdateTarget();

Keyboard.ClearFocus();

}

}

private void OnTextBoxRename_KeyDown(object sender, KeyEventArgs e)

{

var textBox = sender as TextBox;

var exp = textBox.GetBindingExpression(TextBox.TextProperty);

if (exp == null) return;

if (e.Key == Key.Enter)

{

if (textBox.Tag is ICommand command && command.CanExecute(textBox.Text))

{

command.Execute(textBox.Text);

}

else

{

exp.UpdateSource();

}

textBox.Visibility = Visibility.Collapsed;

e.Handled = true;

}

else if (e.Key == Key.Escape)

{

exp.UpdateTarget();

textBox.Visibility = Visibility.Collapsed;

}

}

private void OnTextBoxRename_LostFocus(object sender, RoutedEventArgs e)

{

var textBox = sender as TextBox;

if (!textBox.IsVisible) return;

var exp = textBox.GetBindingExpression(TextBox.TextProperty);

if (exp != null)

{

exp.UpdateTarget();

textBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));

}

}

private void OnClose_Button_Click(object sender, RoutedEventArgs e)

{

var window = (Window)((FrameworkElement)sender).TemplatedParent;

window.Close();

}

private void OnMaximizeRestor_Button_Click(object sender, RoutedEventArgs e)

{

var window = (Window)((FrameworkElement)sender).TemplatedParent;

window.WindowState = (window.WindowState == WindowState.Normal) ? WindowState.Maximized : WindowState.Normal;

}

private void OnMaximize_Button_Click(object sender, RoutedEventArgs e)

{

var window = (Window)((FrameworkElement)sender).TemplatedParent;

window.WindowState = WindowState.Maximized;

}

}

}

相关推荐
枯萎穿心攻击2 小时前
响应式编程入门教程第二节:构建 ObservableProperty<T> — 封装 ReactiveProperty 的高级用法
开发语言·unity·c#·游戏引擎
X_StarX10 小时前
【Unity笔记02】订阅事件-自动开门
笔记·学习·unity·游戏引擎·游戏开发·大学生
霸王•吕布14 小时前
游戏引擎中顶点着色&像素着色
游戏引擎·顶点着色器·像素着色器·顶点颜色·顶点uv·顶点法向
Thomas_YXQ17 小时前
Unity URP法线贴图实现教程
开发语言·unity·性能优化·游戏引擎·unity3d·贴图·单一职责原则
徐子竣1 天前
[学习记录]Unity-Shader-几何着色器
unity·游戏引擎·着色器
qq_392397121 天前
Redis常用操作
数据库·redis·wpf
三千道应用题1 天前
WPF学习笔记(25)MVVM框架与项目实例
wpf
幻世界1 天前
【Unity智能模型系列】Unity + MediaPipe + Sentis + ArcFace模型:构建高效人脸识别比对系统
unity·游戏引擎
厦门德仔2 天前
【WPF】WPF(样式)
android·java·wpf
漫游者Nova2 天前
虚幻引擎Unreal Engine5恐怖游戏设计制作教程,从入门到精通从零开始完整项目开发实战详细讲解中英字幕
ue5·游戏引擎·虚幻·游戏开发完整教程·恐怖游戏开发