用户控制数字键盘

时间:2015-07-03 16:45:40

标签: wpf controls

我正在创建控制数字键盘。我想以这样的方式设计它,当我按下任何按钮时它的值应该进入聚焦区域。这样我就可以将这个数字控件放在任何地方。我在wpf创建了这个。

wpf中是否有 sendkey 方法?

代码:

<UserControl x:Class="UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="212" Background="Black" >
    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  >
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>

        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"/>
        <ColumnDefinition Width="1*"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <Button Name="btn2" Content="2" Focusable="False"  FontSize="26"  HorizontalAlignment="Stretch"   VerticalAlignment="Stretch" Grid.Column="1" Grid.Row=" 1" />
    <Button Name="btn1" Content="1" Focusable="False" FontSize="26" HorizontalAlignment="Stretch"   Grid.Row="1" VerticalAlignment="Stretch" BorderBrush="DarkGray"  BorderThickness="4,2,2,8"  />
    <Button Name="btn3" Content="3" Focusable="False" FontSize="26" Grid.Column="2" Foreground="White"  HorizontalAlignment="Stretch"   Grid.Row="1" VerticalAlignment="Stretch"  />
    <Button Name="btn4" Content="4" Focusable="False"  FontSize="26" HorizontalAlignment="Stretch"   Grid.Row="2" VerticalAlignment="Stretch"  />
    <Button Name="btn5" Content="5" Focusable="False" FontSize="26" Grid.Column="1" HorizontalAlignment="Stretch"   Grid.Row="2" VerticalAlignment="Stretch"  />
    <Button Name="btn6" Content="6" Focusable="False" FontSize="26" Grid.Column="2" HorizontalAlignment="Stretch"  Grid.Row="2" VerticalAlignment="Stretch"  />
    <Button Name="btn7" Content="7" Focusable="False" FontSize="26" HorizontalAlignment="Stretch"   Grid.Row="3" VerticalAlignment="Stretch"  />
    <Button Name="btn8" Content="8" Focusable="False" FontSize="26" Grid.Column="1" HorizontalAlignment="Stretch"  Grid.Row="3" VerticalAlignment="Stretch"  />
    <Button Name="btn9" Content="9" Focusable="False" FontSize="26" Grid.Column="2" HorizontalAlignment="Stretch"   Grid.Row="3" VerticalAlignment="Stretch"   />
    <Button Name="btn0" Content="0" Focusable="False" FontSize="26" HorizontalAlignment="Stretch"  Grid.Row="4" VerticalAlignment="Stretch"  />
    <Button Name="btn00" Content="00" Focusable="False" FontSize="26" Grid.Column="1" HorizontalAlignment="Stretch"   Grid.Row="4" VerticalAlignment="Stretch"  />
    <Button Name="btn_dot" Content="." Focusable="False" FontSize="26" Grid.Column="2" HorizontalAlignment="Stretch"   Grid.Row="4" VerticalAlignment="Stretch"  />
    <Button Name="btn_temp1" Content="Button" Focusable="False" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" />
    <Button Name="btn_temp2" Content="Button" Focusable="False" Grid.Column="1" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" />
    <Button Name="btn_temp3" Content="Button" Focusable="False" Grid.Column="2" HorizontalAlignment="Stretch"   VerticalAlignment="Stretch"  />
</Grid>

这是我的xaml代码

0 个答案:

没有答案