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;

}

}

}

相关推荐
风酥糖1 小时前
Godot游戏练习01-第20节-增加亿点点细节
游戏·游戏引擎·godot
智算菩萨3 小时前
【OpenGL】6 真实感光照渲染实战:Phong模型、材质系统与PBR基础
开发语言·python·游戏引擎·游戏程序·pygame·材质·opengl
心前阳光7 小时前
Unity之ScrollRect简易实现
unity·游戏引擎
KaGme14 小时前
生成3DGS场景在unity中的呈现
3d·unity·游戏引擎
zyh______1 天前
关于unity的序列化
unity·游戏引擎
IT小哥哥呀1 天前
基于windows的个人/团队的时间管理工具
windows·c#·wpf·时间管理
weixin_409383121 天前
godot碰撞测试的学习
学习·游戏引擎·godot
电子云与长程纠缠1 天前
Godot学习06 - AnimationPlayer内置动画
学习·游戏引擎·godot
mxwin1 天前
Unity Shader 齐次坐标与透视除法理解 SV_POSITION 的 w 分量
unity·游戏引擎·shader
sczmzx1 天前
Cefsharp.WPF高分辨率下崩溃问题解决方案
wpf