Ejemplo n.º 1
0
        public void BindView(params object[] os)
        {
            var tb = new TextBox();
            var cb = new CheckBox();
            var l  = new Label();
            var dp = new DatePicker();

            foreach (var o in os)
            {
                if (o.GetType() == tb.GetType())
                {
                    ((TextBox)o).Bind(this);
                }

                if (o.GetType() == cb.GetType())
                {
                    ((CheckBox)o).Bind(this);
                }

                if (o.GetType() == l.GetType())
                {
                    ((Label)o).Bind(this);
                }

                if (o.GetType() == dp.GetType())
                {
                    ((DatePicker)o).Bind(this);
                }
            }
        }
Ejemplo n.º 2
0
        public void ChangeView(params object[] os)
        {
            var tb  = new TextBox();
            var l   = new Label();
            var dp  = new DatePicker();
            var cmb = new ComboBox();

            foreach (var o in os)
            {
                if (o.GetType() == tb.GetType())
                {
                    ((TextBox)o).Text = this.GetType().GetProperty(((TextBox)o).Name).GetValue(this).ToString();
                }

                if (o.GetType() == cmb.GetType())
                {
                    ((ComboBox)o).SelectedValue = this.GetType().GetProperty(((ComboBox)o).Name).GetValue(this);
                }

                if (o.GetType() == l.GetType())
                {
                    ((Label)o).Content = this.GetType().GetProperty(((Label)o).Name).GetValue(this).ToString();
                }

                if (o.GetType() == dp.GetType())
                {
                    ((DatePicker)o).Text = this.GetType().GetProperty(((DatePicker)o).Name).GetValue(this).ToString();
                }
            }
        }
Ejemplo n.º 3
0
        private void datePickerDateColumn_Loaded(object sender, RoutedEventArgs e)
        {
            DatePicker picker = sender as DatePicker;

            FieldInfo fiTextBox = picker.GetType().GetField("_textBox", BindingFlags.Instance | BindingFlags.NonPublic);

            if (fiTextBox != null)
            {
                var dateTextBox = fiTextBox.GetValue(picker);

                if (dateTextBox != null)
                {
                    PropertyInfo piWatermark = dateTextBox.GetType()
                                               .GetProperty("Watermark", BindingFlags.Instance | BindingFlags.NonPublic);

                    if (piWatermark != null)
                    {
                        piWatermark.SetValue(dateTextBox, "No date", null);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void UpdateSources(params object[] os)
        {
            var tb  = new TextBox();
            var cb  = new CheckBox();
            var l   = new Label();
            var dp  = new DatePicker();
            var cmb = new ComboBox();

            foreach (var o in os)
            {
                if (o.GetType() == tb.GetType())
                {
                    ((TextBox)o).GetBindingExpression(TextBox.TextProperty).UpdateSource();
                }

                if (o.GetType() == cb.GetType())
                {
                    ((CheckBox)o).GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
                }

                if (o.GetType() == l.GetType())
                {
                    ((Label)o).GetBindingExpression(Label.ContentProperty).UpdateSource();
                }

                if (o.GetType() == dp.GetType())
                {
                    ((DatePicker)o).GetBindingExpression(DatePicker.TextProperty).UpdateSource();
                }

                if (o.GetType() == cmb.GetType())
                {
                    ((ComboBox)o).GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
                }
            }
        }
Ejemplo n.º 5
0
        public void DatePicker_AutomationPeer()
        {
            _elementToCleanUp = new DatePicker();
            _isLoaded         = false;
            DatePickerAutomationPeer datePickerAutomationPeer = (DatePickerAutomationPeer)DatePickerAutomationPeer.CreatePeerForElement(_elementToCleanUp);

            Assert.IsNotNull(datePickerAutomationPeer);

            DateTime date = new DateTime(2000, 2, 2);

            _elementToCleanUp.SelectedDate = date;
            _elementToCleanUp.Height       = 30;
            _elementToCleanUp.Width        = 100;
            _elementToCleanUp.Loaded      += new RoutedEventHandler(_elementToCleanUp_Loaded);
            TestPanel.Children.Add(_elementToCleanUp);
            EnqueueConditional(IsLoaded);
            DateTime date2 = new DateTime(2000, 5, 5);

            EnqueueCallback(delegate
            {
                Assert.AreEqual(datePickerAutomationPeer.GetAutomationControlType(), AutomationControlType.ComboBox, "Incorrect Control type for datepicker");
                Assert.AreEqual(datePickerAutomationPeer.GetClassName(), _elementToCleanUp.GetType().Name, "Incorrect ClassName value for datepicker");
                Assert.AreEqual(datePickerAutomationPeer.GetName(), date.ToString(), "Incorrect Name value for datepickerpeer");
                Assert.IsTrue(datePickerAutomationPeer.IsContentElement(), "Incorrect IsContentElement value");
                Assert.IsTrue(datePickerAutomationPeer.IsControlElement(), "Incorrect IsControlElement value");

                #region DatePickerAutomationPeer IExpandCollapseProvider tests:

                IExpandCollapseProvider datePickerExpandCollapseProvider = ((IExpandCollapseProvider)datePickerAutomationPeer.GetPattern(PatternInterface.ExpandCollapse));
                Assert.IsNotNull(datePickerAutomationPeer);
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Collapsed);
                _elementToCleanUp.IsDropDownOpen = true;
                Assert.IsTrue(_elementToCleanUp.TestHook.DropDown.IsOpen);
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Expanded);
                datePickerExpandCollapseProvider.Collapse();
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Collapsed);
                Assert.IsFalse(_elementToCleanUp.TestHook.DropDown.IsOpen);
                datePickerExpandCollapseProvider.Expand();
                Assert.IsTrue(_elementToCleanUp.TestHook.DropDown.IsOpen);
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Expanded);
                datePickerExpandCollapseProvider.Collapse();

                #endregion

                #region DatePickerAutomationPeer IValueProvider tests:

                IValueProvider datePickerValueProvider = ((IValueProvider)datePickerAutomationPeer.GetPattern(PatternInterface.Value));
                Assert.IsNotNull(datePickerValueProvider);
                Assert.IsFalse(datePickerValueProvider.IsReadOnly);
                Assert.AreEqual(datePickerValueProvider.Value, date.ToString());
                _elementToCleanUp.SelectedDate = null;
                Assert.AreEqual(datePickerValueProvider.Value, string.Empty);
                datePickerValueProvider.SetValue(date2.ToString());
                Assert.AreEqual(_elementToCleanUp.SelectedDate, date2);
                Assert.AreEqual(datePickerValueProvider.Value, date2.ToString());
                #endregion
            });
            EnqueueSleep(sleepTime);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(_elementToCleanUp.Text, date2.ToString("d"));
            });

            EnqueueTestComplete();
        }
Ejemplo n.º 6
0
        [Description("Tests the creation of an automation peer for the DatePicker")]
        public void DatePicker_AutomationPeer()
        {
            _elementToCleanUp = new DatePicker();
            _isLoaded = false;
            DatePickerAutomationPeer datePickerAutomationPeer = (DatePickerAutomationPeer)DatePickerAutomationPeer.CreatePeerForElement(_elementToCleanUp);
            Assert.IsNotNull(datePickerAutomationPeer);

            DateTime date = new DateTime(2000, 2, 2);
            _elementToCleanUp.SelectedDate = date;
            _elementToCleanUp.Height = 30;
            _elementToCleanUp.Width = 100;
            _elementToCleanUp.Loaded += new RoutedEventHandler(_elementToCleanUp_Loaded);
            TestPanel.Children.Add(_elementToCleanUp);
            EnqueueConditional(IsLoaded);
            DateTime date2 = new DateTime(2000, 5, 5);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(datePickerAutomationPeer.GetAutomationControlType(), AutomationControlType.ComboBox, "Incorrect Control type for datepicker");
                Assert.AreEqual(datePickerAutomationPeer.GetClassName(), _elementToCleanUp.GetType().Name, "Incorrect ClassName value for datepicker");
                Assert.AreEqual(datePickerAutomationPeer.GetName(), date.ToString(), "Incorrect Name value for datepickerpeer");
                Assert.IsTrue(datePickerAutomationPeer.IsContentElement(), "Incorrect IsContentElement value");
                Assert.IsTrue(datePickerAutomationPeer.IsControlElement(), "Incorrect IsControlElement value");

                #region DatePickerAutomationPeer IExpandCollapseProvider tests:

                IExpandCollapseProvider datePickerExpandCollapseProvider = ((IExpandCollapseProvider)datePickerAutomationPeer.GetPattern(PatternInterface.ExpandCollapse));
                Assert.IsNotNull(datePickerAutomationPeer);
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Collapsed);
                _elementToCleanUp.IsDropDownOpen = true;
                Assert.IsTrue(_elementToCleanUp.TestHook.DropDown.IsOpen);
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Expanded);
                datePickerExpandCollapseProvider.Collapse();
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Collapsed);
                Assert.IsFalse(_elementToCleanUp.TestHook.DropDown.IsOpen);
                datePickerExpandCollapseProvider.Expand();
                Assert.IsTrue(_elementToCleanUp.TestHook.DropDown.IsOpen);
                Assert.AreEqual(datePickerExpandCollapseProvider.ExpandCollapseState, ExpandCollapseState.Expanded);
                datePickerExpandCollapseProvider.Collapse();

                #endregion

                #region DatePickerAutomationPeer IValueProvider tests:

                IValueProvider datePickerValueProvider = ((IValueProvider)datePickerAutomationPeer.GetPattern(PatternInterface.Value));
                Assert.IsNotNull(datePickerValueProvider);
                Assert.IsFalse(datePickerValueProvider.IsReadOnly);
                Assert.AreEqual(datePickerValueProvider.Value, date.ToString());
                _elementToCleanUp.SelectedDate = null;
                Assert.AreEqual(datePickerValueProvider.Value, string.Empty);
                datePickerValueProvider.SetValue(date2.ToString());
                Assert.AreEqual(_elementToCleanUp.SelectedDate, date2);
                Assert.AreEqual(datePickerValueProvider.Value, date2.ToString());
                #endregion
            });
            EnqueueSleep(sleepTime);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(_elementToCleanUp.Text, date2.ToString("d"));
            });

            EnqueueTestComplete();
Ejemplo n.º 7
0
        private void WriteToDataGrid(string file, TabItem tab)
        {
            try
            {
                int sheetIndex = tabControl.Items.IndexOf(tab);

                string prefab = App.GetPrefabFromDatabase(file);
                MasterData.Add(App.ToDataTable(App.GetItems(file, prefab), prefab));

                DataGrid dataGrid = new DataGrid();
                dataGrid.AutoGenerateColumns = true;

                dataGrid.AutoGeneratedColumns += (sender, args) =>
                {
                    Prop prop = App.GetProp(prefab, "Types");

                    for (int i = 0; i < dataGrid.Columns.Count; i++)
                    {
                        //Console.WriteLine(prop.Get("field" + i));
                        DataGridColumn column = dataGrid.Columns[i];
                        if (prop.Get("field" + i).ToLower().Equals("combobox"))
                        {
                            column        = new DataGridComboBoxColumn();
                            column.Header = dataGrid.Columns[i].Header;
                            Binding textBinding = new Binding(dataGrid.Columns[i].Header.ToString());
                            textBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                            textBinding.Mode = BindingMode.TwoWay;
                            textBinding.BindsDirectlyToSource            = true;
                            ((DataGridComboBoxColumn)column).TextBinding = textBinding;

                            ComboBox comboBox = new ComboBox();
                            comboBox.IsEditable = true;

                            Prop          comboBoxProp = App.GetComboBoxProp(prefab, i);
                            List <string> comboStrings = new List <string>();
                            for (int j = 0; j < comboBoxProp.Count; j++)
                            {
                                comboStrings.Add(comboBoxProp.Get("comboChoice" + j));
                            }

                            ((DataGridComboBoxColumn)column).ItemsSource = comboStrings;

                            Style style = new Style(comboBox.GetType());
                            DependencyProperty property = ComboBox.IsEditableProperty;
                            Setter             setter   = new Setter(property, true);
                            //Console.WriteLine(setter.Value);
                            style.Setters.Add(setter);

                            ((DataGridComboBoxColumn)column).EditingElementStyle = style;
                            dataGrid.Columns[i] = column;
                        }
                        else if (prop.Get("field" + i).ToLower().Equals("datepicker"))
                        {
                            column        = new DataGridTextColumn();
                            column.Header = dataGrid.Columns[i].Header;

                            DatePicker         datePicker = new DatePicker();
                            Style              style      = new Style(datePicker.GetType());
                            DependencyProperty property   = DatePicker.SelectedDateFormatProperty;
                            Setter             setter     = new Setter(property, DatePickerFormat.Long);
                            style.Setters.Add(setter);
                            datePicker.Style    = style;
                            datePicker.KeyDown += (o, eventArgs) =>
                            {
                                if (eventArgs.Key == Key.Enter)
                                {
                                    datePicker.Text = DateTime.Now.ToShortDateString();
                                }
                            };

                            FrameworkElementFactory datePickerFactoryElem = new FrameworkElementFactory(datePicker.GetType());

                            Binding dateBind = new Binding(dataGrid.Columns[i].Header.ToString());
                            dateBind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                            dateBind.Mode = BindingMode.TwoWay;
                            dateBind.BindsDirectlyToSource = true;

                            datePickerFactoryElem.SetValue(DatePicker.SelectedDateProperty, dateBind);
                            datePickerFactoryElem.SetValue(DatePicker.DisplayDateProperty, dateBind);

                            DataTemplate cellTemplate = new DataTemplate(datePicker.GetType());
                            cellTemplate.VisualTree = datePickerFactoryElem;
                            ((DataGridTextColumn)column).EditingElementStyle = style;
                            dataGrid.Columns[i] = column;
                        }
                        else if (prop.Get("field" + i).ToLower().Equals("checkbox"))
                        {
                            column        = new DataGridCheckBoxColumn();
                            column.Header = dataGrid.Columns[i].Header;
                            Binding checkBoxBinding = new Binding(dataGrid.Columns[i].Header.ToString());
                            checkBoxBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                            checkBoxBinding.Mode = BindingMode.TwoWay;
                            checkBoxBinding.BindsDirectlyToSource    = true;
                            ((DataGridCheckBoxColumn)column).Binding = checkBoxBinding;
                            dataGrid.Columns[i] = column;
                        }
                    }
                };
                DataTable table = MasterData[sheetIndex];
                dataGrid.ItemsSource = table.DefaultView;

                dataGrid.LoadingRow += OnLoadingRow;

                dataGrid.SelectionUnit         = DataGridSelectionUnit.CellOrRowHeader;
                dataGrid.SelectionMode         = DataGridSelectionMode.Extended;
                dataGrid.CanUserSortColumns    = false;
                dataGrid.CanUserReorderColumns = false;
                dataGrid.IsEnabled             = true;

                //dataGrid.Loaded += (s, o) => { Console.WriteLine(dataGrid.Columns.Count.ToString()); };

                //addListeners(dataGrid, sheetIndex);

                //addFilter(dataGrid, sheetIndex);

                tab.Content = dataGrid;
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }
        }