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;

}

}

}

相关推荐
技术小甜甜3 小时前
[Godot] 解决导出APK安装失败的常见问题:深入分析与调试方法
游戏引擎·godot·游戏开发
技术小甜甜7 小时前
[Godot][入门] 安装与版本选择:3.x 还是 4.x?(按项目类型一键决策)
游戏引擎·godot·游戏开发·2d
陈言必行8 小时前
Unity 之 物理引擎中三种刚体力施加方式详解
unity·游戏引擎
foreveryao1238 小时前
Unity渲染流程(底层逻辑)
unity·游戏引擎·图形渲染
small-pudding8 小时前
Unity中的PBR(基于物理的渲染)
unity·游戏引擎
没有bug.的程序员1 天前
SOA、微服务、分布式系统的区别与联系
java·jvm·微服务·架构·wpf·日志·gc
Macbethad1 天前
基于WPF的半导体设备配方管理程序技术方案
wpf
鹿野素材屋1 天前
动作游戏网游:帧同步下的动画同步
unity·游戏引擎
FuckPatience1 天前
WPF Geometry
wpf
WMX10121 天前
Unity添加近身菜单-MRTK
unity·游戏引擎