RoutedUICommand 路由命令调试

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





      本文转自daniel8294 51CTO博客,原文链接:http://blog.51cto.com/acadia627/1731185,如需转载请自行联系原作者




相关文章:

  • 2021-11-20
  • 2021-12-22
  • 2021-11-30
  • 2022-02-19
  • 2021-07-01
  • 2021-12-11
  • 2021-12-31
  • 2021-11-30
猜你喜欢
  • 2021-12-12
  • 2021-06-21
  • 2021-07-29
  • 2021-12-18
  • 2021-12-18
  • 2021-08-13
  • 2021-09-24
相关资源
相似解决方案