none
При вызове FocusManager.SetFocusedElement(focusScope, mText) получаю ошибку "Входная строка имела неверный формат." RRS feed

  • Общие обсуждения

  • В mText.Text в это время содержится ноль. Вот xaml компонента:

     <Controls:CTSelectionBindingMaskTextBox    PreviewLostKeyboardFocus="mText_PreviewLostKeyboardFocus" 
                                                    Canvas.Left="{Binding Path=X,UpdateSourceTrigger=PropertyChanged}" Canvas.Top="{Binding Path=Y,UpdateSourceTrigger=PropertyChanged}" 
                Width="Auto" SizeChanged="mText_SizeChanged" AcceptsReturn="False"
                              FocusManager.IsFocusScope="{Binding Path=FocusScopeValue1,Mode=OneWayToSource,UpdateSourceTrigger=PropertyChanged}"
                                                            Text="{Binding Path=Scene.Value11,UpdateSourceTrigger=PropertyChanged}" Height="Auto" x:Name="mText" 
    Visibility="{Binding Path=Scene.IsOpen,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource VisibilityConverter}}">
                    <Controls:CTSelectionBindingMaskTextBox.InputBindings>
                        <KeyBinding Key="Return"  Command="{Binding Path=EndDrawing}">
    
                        </KeyBinding>
                        <KeyBinding Key="Space"  Command="{Binding Path=EndDrawing}">
    
                        </KeyBinding>
                        <KeyBinding Key="Tab"  Command="{Binding Path=EndDrawing}">
    
                        </KeyBinding>
                    </Controls:CTSelectionBindingMaskTextBox.InputBindings>
                </Controls:CTSelectionBindingMaskTextBox>

    вот класс CTSelectionBindingMaskTextBox:

     public  class CTSelectionBindingMaskTextBox:MaskedTextBox
        {
            public static readonly DependencyProperty BindableSelectionStartProperty =
    
          DependencyProperty.Register(
    
          "BindableSelectionStart",
    
          typeof(int),
    
          typeof(CTSelectionBindingMaskTextBox),
    
          new PropertyMetadata(OnBindableSelectionStartChanged));
    
    
    
            public static readonly DependencyProperty BindableSelectionLengthProperty =
    
                DependencyProperty.Register(
    
                "BindableSelectionLength",
    
                typeof(int),
    
                typeof(CTSelectionBindingMaskTextBox),
    
                new PropertyMetadata(OnBindableSelectionLengthChanged));
    
    
    
            private bool changeFromUI;
    
    
    
            public CTSelectionBindingMaskTextBox()
    
            : base()
    
        {
    
                this.SelectionChanged += this.OnSelectionChanged;
    
            }
    
    
    
            public int BindableSelectionStart
    
            {
    
                get
    
                {
    
                    return (int)this.GetValue(BindableSelectionStartProperty);
    
                }
    
    
    
                set
    
                {
    
                    this.SetValue(BindableSelectionStartProperty, value);
    
                }
    
            }
    
    
    
            public int BindableSelectionLength
    
            {
    
                get
    
                {
    
                    return (int)this.GetValue(BindableSelectionLengthProperty);
    
                }
    
    
    
                set
    
                {
    
                    this.SetValue(BindableSelectionLengthProperty, value);
    
                }
    
            }
    
    
    
            private static void OnBindableSelectionStartChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
    
            {
    
                var textBox = dependencyObject as CTSelectionBindingMaskTextBox;
    
    
    
                if (!textBox.changeFromUI)
    
                {
    
                    int newValue = (int)args.NewValue;
    
                    textBox.SelectionStart = newValue;
    
                }
    
                else
    
                {
    
                    textBox.changeFromUI = false;
    
                }
    
            }
    
    
    
            private static void OnBindableSelectionLengthChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
    
            {
    
                var textBox = dependencyObject as CTSelectionBindingMaskTextBox;
    
    
    
                if (!textBox.changeFromUI)
    
                {
    
                    int newValue = (int)args.NewValue;
    
                    textBox.SelectionLength = newValue;
    
                }
    
                else
    
                {
    
                    textBox.changeFromUI = false;
    
                }
    
            }
    
    
    
            private void OnSelectionChanged(object sender, RoutedEventArgs e)
    
            {
    
                if (this.BindableSelectionStart != this.SelectionStart)
    
                {
    
                    this.changeFromUI = true;
    
                    this.BindableSelectionStart = this.SelectionStart;
    
                }
    
    
    
                if (this.BindableSelectionLength != this.SelectionLength)
    
                {
    
                    this.changeFromUI = true;
    
                    this.BindableSelectionLength = this.SelectionLength;
    
                }
    
            }
        }
    }
    
    Scene.Value11 имеет тип decimal

    11 февраля 2017 г. 2:37