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;

}

}

}

相关推荐
留待舞人归9 小时前
【Unity3D优化】优化多语言字体包大小
游戏·unity·游戏引擎·unity3d·优化
wsdchong之小马过河10 小时前
2025虚幻引擎一般用什么模型格式
游戏引擎·虚幻
Magnum Lehar17 小时前
wpf游戏引擎前端的Transform.cs实现
前端·游戏引擎·wpf
@Crazy Snail19 小时前
WPF数据绑定疑惑解答--(关于控件的Itemsource,Collection绑定)
windows·wpf·wpf数据绑定
猕员桃20 小时前
《Elasticsearch 分布式搜索在聊天记录检索中的深度优化》
分布式·elasticsearch·wpf
Magnum Lehar20 小时前
wpf3d游戏引擎前端ControlTemplate实现
前端·游戏引擎·wpf
EQ-雪梨蛋花汤1 天前
【Unity笔记】Unity Animation组件使用详解:Play方法重载与动画播放控制
笔记·unity·游戏引擎
AgilityBaby1 天前
Untiy打包安卓踩坑
android·笔记·学习·unity·游戏引擎
天蓝蓝的本我1 天前
WPF加载文本文件时如何设置WebBrowser的字体
wpf