//=============================================================================
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            Property_ViewModel _prop = item as Property_ViewModel;

            if (_prop != null)
            {
                List <string> _stValues = _prop.StandardValues;
                if (_stValues != null && _stValues.Count > 0)
                {
                    return(ComboboxTemplate);
                }

                object _val = _prop.Value;
                if (_val is bool)
                {
                    return(BooleanTemplate);
                }
            }

            return(DefaultTemplate);
        }
Example #2
0
        //=============================================================================
        private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            TextBox tb = sender as TextBox;

            if (tb == null)
            {
                return;
            }

            Property_ViewModel pvm = tb.DataContext as Property_ViewModel;

            if (pvm == null)
            {
                return;
            }

            if (!pvm.IsNumeric)
            {
                return;
            }

            bool bAccept = false;

            // is digit
            if ((e.Key >= Key.D0 && e.Key <= Key.D9) ||
                (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9))
            {
                bAccept = true;
            }
            //
            if (e.Key == Key.Escape || e.Key == Key.Enter || e.Key == Key.Tab || e.Key == Key.Back)
            {
                bAccept = true;
            }

            if (!bAccept)
            {
                e.Handled = true;
            }
        }