从后面的代码激活文本框上的UIElement

时间:2014-10-27 11:32:00

标签: wpf wpf-controls uielement

我有一个自定义WPF键盘,我在我的应用程序中用于输入

xmlns:WpfKb="clr-namespace:WpfKb.Controls;assembly=WpfKb"

在resourcedictionary中

<WpfKb:OnScreenKeypad x:Key="OnScreenKeypad"/>

在我的XAML代码中,我使用以下代码激活:

                    <TextBox Name="Sensor1Yoffset" Width="100" Margin="5,0" Grid.Row="1" Grid.Column="2" Style="{DynamicResource PmEditTextBox}" Text="{Binding Path=SensorOffsetY1}" VerticalContentAlignment="Center"  HorizontalContentAlignment="Center"
                WpfKb:FloatingTouchScreenKeyboard.KeyboardType="{StaticResource OnScreenKeypad}" 
                            WpfKb:FloatingTouchScreenKeyboard.OpenOnFocus="False" 
                            WpfKb:FloatingTouchScreenKeyboard.OpenOnMouseClick="{Binding Path=UseOnScreenKeyboard}" 
                            WpfKb:FloatingTouchScreenKeyboard.Placement="Left" 
                            WpfKb:FloatingTouchScreenKeyboard.PlacementTarget="{Binding ElementName=TheGui}" Grid.ColumnSpan="1" />

现在我需要在后面的代码中添加它,但不知道ro开始寻找的位置。

      TextBox ChannelName = new TextBox();
      ChannelName.Style = (MyView.TryFindResource("PmEditTextBox") as Style);
      ChannelName.Width = 300;

FloatingTouchScreenKeyboardclass定义为

public partial class FloatingTouchScreenKeyboard : System.Windows.Controls.Primitives.Popup
    {
        public static readonly DependencyProperty AreAnimationsEnabledProperty = DependencyProperty.Register("AreAnimationsEnabled", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(true));
        public static readonly DependencyProperty IsAllowedToFadeProperty = DependencyProperty.Register("IsAllowedToFade", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(true));
        public static readonly DependencyProperty IsDraggingProperty = DependencyProperty.Register("IsDragging", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(false));
        public static readonly DependencyProperty IsDragHelperAllowedToHideProperty = DependencyProperty.Register("IsDragHelperAllowedToHide", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(false));
        public static readonly DependencyProperty IsKeyboardShownProperty = DependencyProperty.Register("IsKeyboardShown", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(true));
        public static readonly DependencyProperty MaximumKeyboardOpacityProperty = DependencyProperty.Register("MaximumKeyboardOpacity", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.9d));
        public static readonly DependencyProperty MinimumKeyboardOpacityProperty = DependencyProperty.Register("MinimumKeyboardOpacity", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.2d));
        public static readonly DependencyProperty KeyboardHideDelayProperty = DependencyProperty.Register("KeyboardHideDelay", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(5d));
        public static readonly DependencyProperty KeyboardHideAnimationDurationProperty = DependencyProperty.Register("KeyboardHideAnimationDuration", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.5d));
        public static readonly DependencyProperty KeyboardShowAnimationDurationProperty = DependencyProperty.Register("KeyboardShowAnimationDuration", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.5d));
        public static readonly DependencyProperty DeadZoneProperty = DependencyProperty.Register("DeadZone", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(5d));

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您设置的大多数附加属性实际上是由浮动键盘的基类Popup公开的。 Popup类具有可用于从C#代码设置属性的setter方法,例如:

Popup.SetPlacementTarget(ChannelName, TheGui)

对于带有绑定的属性,请使用目标SetBinding方法:

ChannelName.SetBinding(
    Popup.OpenOnMouseClickProperty,
    new Binding
    {
        Path = new PropertyPath("UseOnScreenKeyboard")
    });

查看WpfKb项目,我没有看到KeyboardType属性的任何定义。也许它存在于早期版本中,或者您使用的是自定义/分叉版本?