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;

}

}

}

相关推荐
三千道应用题25 分钟前
WPF&C#超市管理系统(6)订单详情、顾客注册、商品销售排行查询和库存提示、LiveChat报表
开发语言·c#·wpf
✎ ﹏梦醒͜ღ҉繁华落℘18 小时前
开发WPF项目时遇到的问题总结
wpf
hqwest2 天前
C#WPF实战出真汁06--【系统设置】--餐桌类型设置
c#·.net·wpf·布局·分页·命令·viewmodel
Vae_Mars2 天前
WPF中使用InputBindings进行快捷键绑定
wpf
hqwest2 天前
C#WPF实战出真汁05--左侧导航
开发语言·c#·wpf·主界面·窗体设计·视图viewmodel
hqwest2 天前
C#WPF实战出真汁01--项目介绍
开发语言·c#·wpf
wuty0073 天前
WPF 实现支持动态调整高度的文本显示控件
wpf·scrollviewer·extentheight·自动高度控件·动态调整高度
霜绛3 天前
Unity:GUI笔记(一)——文本、按钮、多选框和单选框、输入框和拖动条、图片绘制和框绘制
笔记·学习·unity·游戏引擎
YF云飞4 天前
Unity图片优化与比例控制全攻略
游戏·unity·游戏引擎·游戏程序·个人开发
5 天前
Unity 遮挡显示效果 Shader
unity·游戏引擎