Пример #1
0
        internal static HighlightRitchTextBox GetVerseAsTextBox(int bibleId, BibleVerseModel verse, int column)
        {
            HighlightRitchTextBox result = new HighlightRitchTextBox
            {
                Text        = verse.VerseText,
                Tag         = verse,
                BorderBrush = Brushes.Transparent,
                IsReadOnly  = true,
                Margin      = new Thickness(2, 0, 0, 15)
            };

            List <HighlightVerseModel> verseColours = BiblesData.Database.GetVerseColours(verse.BibleVerseKey);

            foreach (HighlightVerseModel colour in verseColours)
            {
                string[] itemSplit = colour.BibleVerseKeyId.Split(BibleLoader.veseSplitValues);

                result.HighlightText(itemSplit[1].ToInt32(), itemSplit[2].ToInt32(), ColourConverters.GetBrushfromHex(colour.HexColour));
            }

            Grid.SetRow(result, (Formatters.GetVerseFromKey(verse.BibleVerseKey) - 1));

            Grid.SetColumn(result, column);

            return(result);
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                string color = System.Convert.ToString(values[0]);

                return(ColourConverters.GetBrushfromHex(color));
            }
            catch
            {
                return(System.Windows.DependencyProperty.UnsetValue);
            }
        }
        public void SetValue(object value)
        {
            switch (this.ObjectType)
            {
            case ModelItemTypeEnum.CheckBox:

                ((CheckBoxItem)this.contentObject).IsChecked = value.TryToBool();

                break;

            case ModelItemTypeEnum.ComboBox:
            case ModelItemTypeEnum.EnumBox:

                ((ComboBoxTool)this.contentObject).SelectedValue = value;

                break;

            case ModelItemTypeEnum.DatePicker:

                ((DatePicker)this.contentObject).SelectedDate = value.TryToDate();

                break;

            case ModelItemTypeEnum.SecureString:

                ((PasswordBoxBindable)this.contentObject).Password = value.ParseToString();

                break;

            case ModelItemTypeEnum.ColorBox:

                TextBoxItem color = (TextBoxItem)this.contentObject;

                color.Background = ColourConverters.GetBrushfromHex(value.ParseToString());

                color.Foreground = ColourConverters.InvertFromHex(value.ParseToString());

                goto default;

            case ModelItemTypeEnum.TextBox:
            default:

                ((TextBoxItem)this.contentObject).Text = value.ParseToString();

                break;
            }
        }
        private void Item_Focuesd(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.ModelViewItemGotFocus != null)
                {
                    this.ModelViewItemGotFocus(this, this.contentObject);
                }

                if (this.ObjectType == ModelItemTypeEnum.ColorBox)
                {
                    TextBoxItem text = (TextBoxItem)sender;

                    text.Background = ColourConverters.GetBrushfromHex(text.Text);

                    text.Foreground = ColourConverters.InvertFromHex(text.Text);
                }
            }
            catch
            {
                // DO NOTHING
            }
        }
        private void CreateContent(object parentObject, FieldInformationAttribute fieldValues)
        {
            BindingMode bindingMode = this.PropertyInfo.CanRead && this.PropertyInfo.CanWrite ? BindingMode.TwoWay :
                                      this.PropertyInfo.CanWrite ? BindingMode.OneWayToSource : BindingMode.OneWay;

            Binding binding = new Binding(this.PropertyInfo.Name)
            {
                Path   = new PropertyPath(this.PropertyInfo.Name),
                Source = parentObject,
                Mode   = bindingMode,
                BindsDirectlyToSource = true,
            };

            binding.ValidationRules.Add(new IsRequiredValidationRule {
                IsRequired = fieldValues.IsRequired, ObjectType = this.ObjectType
            });

            this.IsTabStop = !fieldValues.IsReadOnly;

            switch (this.ObjectType)
            {
            case ModelItemTypeEnum.CheckBox:

                #region CHECK BOX

                CheckBoxItem check = new CheckBoxItem {
                    IsEnabled = !fieldValues.IsReadOnly
                };

                check.GotFocus += this.Item_Focuesd;

                this.DependencyProperty = CheckBoxItem.IsCheckedProperty;

                check.SetBinding(CheckBoxItem.IsCheckedProperty, binding);

                this.BindingExpression = check.GetBindingExpression(CheckBoxItem.IsCheckedProperty);

                this.contentObject = check;

                break;

                #endregion

            case ModelItemTypeEnum.ComboBox:
            case ModelItemTypeEnum.EnumBox:

                #region COMBO BOX

                ComboBoxTool comboBox = new ComboBoxTool {
                    IsEnabled = !fieldValues.IsReadOnly, IsEditable = this.isComboBoxEdit
                };

                comboBox.HorizontalAlignment = HorizontalAlignment.Stretch;

                comboBox.GotFocus += this.Item_Focuesd;

                this.LoadContentValues(parentObject, comboBox);

                this.DependencyProperty = this.isComboBoxEdit ? ComboBoxTool.TextProperty : ComboBoxTool.ItemKeyProperty;

                comboBox.SetBinding(this.isComboBoxEdit ? ComboBoxTool.TextProperty : ComboBoxTool.ItemKeyProperty, binding);

                this.BindingExpression = comboBox.GetBindingExpression(this.isComboBoxEdit ? ComboBoxTool.TextProperty : ComboBoxTool.ItemKeyProperty);

                this.contentObject = comboBox;

                break;

                #endregion

            case ModelItemTypeEnum.DatePicker:

                #region DATE PICKER

                DatePicker date = new DatePicker {
                    IsEnabled = !fieldValues.IsReadOnly
                };

                //binding.ValidationRules.Clear();

                date.HorizontalAlignment = HorizontalAlignment.Stretch;

                date.GotFocus += this.Item_Focuesd;

                this.DependencyProperty = DatePicker.SelectedDateProperty;

                date.SetBinding(DatePicker.SelectedDateProperty, binding);

                this.BindingExpression = date.GetBindingExpression(DatePicker.SelectedDateProperty);

                this.contentObject = date;

                break;

                #endregion

            case ModelItemTypeEnum.SecureString:

                #region SECURE STRING

                PasswordBoxBindable pass = new PasswordBoxBindable(parentObject)
                {
                    IsEnabled = !fieldValues.IsReadOnly
                };

                pass.HorizontalAlignment = HorizontalAlignment.Stretch;

                pass.HorizontalContentAlignment = HorizontalAlignment.Stretch;

                pass.LostFocus += this.Item_Focuesd;

                this.DependencyProperty = PasswordBoxBindable.PasswordTextProperty;

                pass.SetBinding(PasswordBoxBindable.PasswordTextProperty, binding);

                this.BindingExpression = pass.GetBindingExpression(PasswordBoxBindable.PasswordTextProperty);

                this.contentObject = pass;

                break;

                #endregion

            case ModelItemTypeEnum.ColorBox:
            case ModelItemTypeEnum.TextBox:
            default:

                #region TEXT BOX (DEFAULT)

                TextBoxItem text = new TextBoxItem {
                    IsReadOnly = fieldValues.IsReadOnly, TextWrapping = TextWrapping.WrapWithOverflow
                };

                text.MaxHeight = 250;

                text.MaxLength = fieldValues.MaxTextLength;

                text.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

                text.HorizontalAlignment = HorizontalAlignment.Stretch;

                text.HorizontalContentAlignment = HorizontalAlignment.Stretch;

                text.SpellCheck.IsEnabled = this.isSpellCheck;

                text.LostFocus += this.Item_Focuesd;

                this.DependencyProperty = TextBoxItem.TextProperty;

                text.SetBinding(TextBoxItem.TextProperty, binding);

                this.BindingExpression = text.GetBindingExpression(TextBoxItem.TextProperty);

                this.contentObject = text;

                if (this.ObjectType == ModelItemTypeEnum.ColorBox && !text.Text.IsNullEmptyOrWhiteSpace())
                {
                    text.Background = ColourConverters.GetBrushfromHex(text.Text);

                    text.Foreground = ColourConverters.InvertFromHex(text.Text);
                }

                break;

                #endregion
            }

            this.uxContent.Content = this.contentObject;
        }