RoutedUICommand 路由命令调试
2016-01-03 22:22
471 查看
![](http://s2.51cto.com/wyfs02/M01/79/1A/wKioL1aJMXKTDVNJAABU__jRitU205.jpg)
前端XAML代码:
<Window x:Class="WpfApplication48.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication48"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<RoutedUICommand x:Key="IncreaseFont" />
<RoutedUICommand x:Key="DecreaseFont" />
</Window.Resources>
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+Alt+I" Command="{StaticResource IncreaseFont}" />
<KeyBinding Gesture="Ctrl+Alt+D" Command="{StaticResource DecreaseFont}" />
</Window.InputBindings>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource IncreaseFont}" Executed="OnIncreaseFont" />
<CommandBinding Command="{StaticResource DecreaseFont}" Executed="OnDecreaseFont" />
</Window.CommandBindings>
<Grid>
<Grid.Resources>
<RoutedUICommand x:Key="IncreaseFont1" />
<RoutedUICommand x:Key="DecreaseFont1" />
</Grid.Resources>
<Grid.CommandBindings>
<CommandBinding Command="{StaticResource IncreaseFont1}" Executed="OnIncreaseFont" />
<CommandBinding Command="{StaticResource DecreaseFont1}" Executed="OnDecreaseFont" />
</Grid.CommandBindings>
<TextBox Name="TB1" Text="Daniel Text" Width="300" Height="150" FontSize="15"/>
<Button x:Name="button" Content="增加字体" HorizontalAlignment="Left" Margin="110,266,0,0" VerticalAlignment="Top" Width="75" Command="{StaticResource IncreaseFont1}" />
<Button x:Name="button1" Content="减小字体" HorizontalAlignment="Left" Margin="325,265,0,0" VerticalAlignment="Top" Width="75" Command="{StaticResource DecreaseFont1}"/>
</Grid>
</Window>
后台C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication48
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void OnIncreaseFont(object sender, ExecutedRoutedEventArgs e)
{
TB1.FontSize += 5;
}
public void OnDecreaseFont(object sender, ExecutedRoutedEventArgs e)
{
TB1.FontSize -= 5;
}
}
}
参考链接:
http://kb.cnblogs.com/page/68526/
相关文章推荐
- UIImageView和UIButton的相同点和不同点
- UILabel 文字靠右显示 并且 文字尾部距UILabel有一定的距离,使用attributeString
- JSP页面数据传递中文乱码- request.getParameter()
- JS模块化工具requirejs教程(二):基本知识
- JS模块化工具requirejs教程(二):基本知识
- JS模块化工具requirejs教程(二):基本知识
- UICollectionView
- MVC项目中如何用JS导出EasyUI DataGrid为Excel
- JAVA图形界面(GUI)之菜单
- JS模块化工具requirejs教程(一):初识requirejs
- JS模块化工具requirejs教程(一):初识requirejs
- JS模块化工具requirejs教程(一):初识requirejs
- JS模块化工具requirejs教程(一):初识requirejs
- UICollectionView: 1>UICollectionViewFlowLayout流式布局
- iOS 疑难杂症(什么鬼系列)— — UITableView 添加 tableFooterView 旋转屏幕后收不到点击事件!!!
- 【非程序问题】building gradle project info一直卡住的解决方法
- 自定义UIButton及注意点
- JAVA图形界面(GUI)之表格
- UIImageView
- 详解UICollectionView