码迷,mamicode.com
首页 > 其他好文 > 详细

RoutedUICommand 路由命令调试

时间:2016-01-04 00:08:27      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:c#   wpf   

技术分享

前端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/


RoutedUICommand 路由命令调试

标签:c#   wpf   

原文地址:http://acadia627.blog.51cto.com/3992605/1731185

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!