public void Add() { SetterBaseCollection sbc = new SetterBaseCollection(); Assert.Throws <ArgumentNullException> (delegate { sbc.Add(null); }, "Add(null)"); Assert.Throws <Exception> (delegate { sbc.Add(new Setter()); }, "Add(Empty)"); }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { base.DeepCopy(source, copyManager); Style s = (Style)source; BasedOn = copyManager.GetCopy(s.BasedOn); foreach (SetterBase setter in s._setters) { _setters.Add(copyManager.GetCopy(setter)); } TargetType = s.TargetType; _resources = copyManager.GetCopy(s.Resources); _owner = copyManager.GetCopy(s._owner); }
public void SetterBaseCollection_Set_Item_Null() { var sbc = new SetterBaseCollection(); sbc.Add(new Setter(Control.PaddingProperty, new Thickness(20d))); Assert.ThrowsException <ArgumentNullException>(() => sbc[0] = null); }
public static void ShowWizard(WizardBase wizard, double width = 800, double height = 800, bool DoNotShowAsDialog = false) { WizardWindow wizardWindow = new WizardWindow(wizard); wizardWindow.Dispatcher.Invoke(() => { wizardWindow.Width = width; wizardWindow.Height = height; if (!wizard.IsNavigationListEnabled) { SetterBaseCollection sbc = wizardWindow.NavigationList.ItemContainerStyle.Setters; sbc.Add(new Setter(ListBoxItem.IsEnabledProperty, wizard.IsNavigationListEnabled)); ((System.Windows.Setter)sbc[sbc.Count - 1]).Value = wizard.IsNavigationListEnabled; } if (DoNotShowAsDialog) { wizardWindow.Owner = App.MainWindow;//adding owner so it will come on top wizardWindow.Show(); } else { wizardWindow.ShowDialog(); } }); }
public void Sealed() { Style style = new Style(typeof(UIElement)); SetterBaseCollection c = style.Setters; Setter s = new Setter(Canvas.LeftProperty, 0); c.Add(s); style.Seal(); Assert.Throws(delegate { c.Add(new Setter(Canvas.TopProperty, 0)); }, typeof(Exception)); Assert.Throws(delegate { c.Insert(0, new Setter(Canvas.TopProperty, 0)); }, typeof(Exception)); /*Assert.Throws (delegate {*/ c.Remove(s); /* }, typeof (Exception));*/ Assert.AreEqual(0, c.Count); // need to reinitialize things here since the // Remove above actually succeeded. style = new Style(typeof(UIElement)); c = style.Setters; s = new Setter(Canvas.LeftProperty, 0); c.Add(s); style.Seal(); // lame, this should raise an exception too /*Assert.Throws (delegate {*/ c.RemoveAt(0); /* }, typeof (Exception));*/ Assert.AreEqual(0, c.Count); // need to reinitialize things here since the // RemoveAt above actually succeeded. style = new Style(typeof(UIElement)); c = style.Setters; s = new Setter(Canvas.LeftProperty, 0); c.Add(s); style.Seal(); Assert.Throws(delegate { c[0] = new Setter(Canvas.TopProperty, 0); }, typeof(Exception)); }
public void SetterBaseCollection_RemoveAt_When_Sealed() { var sbc = new SetterBaseCollection(); sbc.Add(new Setter(Control.IsTabStopProperty, false)); sbc.Seal(); sbc.IsSealed.Should().BeTrue(); Assert.ThrowsException <InvalidOperationException>(() => sbc.RemoveAt(0)); }
public SetterBaseCollection newSetters(txtPreperty property) { SetterBaseCollection setterBases = new SetterBaseCollection(); foreach (SetterBase setterBase in baseStyle.Setters) { setterBases.Add(setterBase); } return(setterBases); }
public void SetterSealedOnAdd() { Setter s = new Setter(UIElement.OpacityProperty, 2.0); SetterBaseCollection sbc = new SetterBaseCollection(); Assert.IsFalse(sbc.IsSealed, "SetterBaseCollection.IsSealed-1"); Assert.IsFalse(s.IsSealed, "Setter.IsSealed-1"); sbc.Add(s); Assert.IsFalse(sbc.IsSealed, "SetterBaseCollection.IsSealed-2"); Assert.IsTrue(s.IsSealed, "Setter.IsSealed-2"); }
public void SetterBaseCollection_Add_When_Sealed() { var sbc = new SetterBaseCollection(); sbc.Seal(); sbc.IsSealed.Should().BeTrue(); var setter = new Setter(Control.PaddingProperty, new Thickness(20d)); Assert.ThrowsException <InvalidOperationException>(() => sbc.Add(setter)); }
private void SealedChildren(bool seal) { Style style = new Style(typeof(UIElement)); SetterBaseCollection c = style.Setters; Setter s = new Setter(Canvas.LeftProperty, 0); c.Add(s); if (seal) { style.Seal(); } // the setter IsSealed status has nothing to do with sealing the style Assert.Throws(delegate { s.Property = Canvas.TopProperty; }, typeof(UnauthorizedAccessException)); Assert.Throws(delegate { s.Value = 10; }, typeof(UnauthorizedAccessException)); }
public void SetterBaseCollection_Add_Null() { var sbc = new SetterBaseCollection(); Assert.ThrowsException <ArgumentNullException>(() => sbc.Add(null)); }
private void BindDataGrid(DataGrid dataGrid) { List <DataGridTextColumn> dataGridTextColumns = new List <DataGridTextColumn>(); SetterBaseCollection setters = (new Style(typeof(DataGridCell))).Setters; Setter setter = new Setter() { Property = HorizontalContentAlignmentProperty, Value = HorizontalAlignment.Right }; setters.Add(setter); DataGridTextColumn dataGridTextColumn = new DataGridTextColumn() { Header = "Date" }; Binding binding = new Binding("date") { Converter = new DateTimeConverter() }; dataGridTextColumn.Binding = binding; dataGridTextColumns.Add(dataGridTextColumn); DataGridTextColumn dataGridTextColumn1 = new DataGridTextColumn() { Header = "Timesheet Code", Binding = new Binding("timesheet_code") }; dataGridTextColumns.Add(dataGridTextColumn1); DataGridTextColumn dataGridTextColumn2 = new DataGridTextColumn() { Header = "Task Type", Binding = new Binding("task_type") }; dataGridTextColumns.Add(dataGridTextColumn2); DataGridTextColumn dataGridTextColumn3 = new DataGridTextColumn() { Header = "Project Serial", Binding = new Binding("project_serial") }; dataGridTextColumns.Add(dataGridTextColumn3); DataGridTextColumn dataGridTextColumn4 = new DataGridTextColumn() { Header = "Section", Binding = new Binding("number_section") }; dataGridTextColumns.Add(dataGridTextColumn4); DataGridTextColumn dataGridTextColumn5 = new DataGridTextColumn() { Header = "Hours" }; Binding binding1 = new Binding("hours") { Converter = new HoursWorkedConverter() }; dataGridTextColumn5.Binding = binding1; dataGridTextColumn5.CellStyle = (Style)base.FindResource("alignRight"); dataGridTextColumns.Add(dataGridTextColumn5); DataGridTextColumn dataGridTextColumn6 = new DataGridTextColumn() { Header = "Description", Binding = new Binding("description") }; dataGridTextColumns.Add(dataGridTextColumn6); DataGridTextColumn dataGridTextColumn7 = new DataGridTextColumn() { Header = "Submitted Status", Binding = new Binding("submitted_status") }; dataGridTextColumns.Add(dataGridTextColumn7); DataGridTextColumn dataGridTextColumn8 = new DataGridTextColumn() { Header = "Approval Status", Binding = new Binding("approval_status") }; dataGridTextColumns.Add(dataGridTextColumn8); DataGridTextColumn dataGridTextColumn9 = new DataGridTextColumn() { Header = "Rejection Reason", Binding = new Binding("rejection_reason") }; dataGridTextColumns.Add(dataGridTextColumn9); foreach (DataGridTextColumn dataGridTextColumn10 in dataGridTextColumns) { dataGridTextColumn10.IsReadOnly = true; dataGrid.Columns.Add(dataGridTextColumn10); } }
private static void LoadSetter(XmlNode StyleSetter, SetterBaseCollection styleSetters) { switch (StyleSetter.Name) { case "TextAlignment": Enum.TryParse(StyleSetter.InnerText, out TextAlignment alignment); Setter textAlignment = new Setter(TextBlock.TextAlignmentProperty, alignment); styleSetters.Add(textAlignment); break; case "Template": StringReader stringReader = new StringReader(StyleSetter.InnerText); XmlReader xmlReader = XmlReader.Create(stringReader); Setter templateSetter = (Setter)XamlReader.Load(xmlReader); styleSetters.Add(templateSetter); break; case "FontFamily": Setter fontFamily = new Setter(DataGridCell.FontFamilyProperty, new FontFamily(StyleSetter.InnerText)); styleSetters.Add(fontFamily); break; case "FontSize": Double.TryParse(StyleSetter.InnerText, out double fontSizeValue); Setter fontSize = new Setter(DataGridCell.FontSizeProperty, fontSizeValue); styleSetters.Add(fontSize); break; case "Background": Setter background = new Setter(DataGridCell.BackgroundProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString(StyleSetter.InnerText))); styleSetters.Add(background); break; case "Foreground": Setter foreground = new Setter(DataGridCell.ForegroundProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString(StyleSetter.InnerText))); styleSetters.Add(foreground); break; case "BorderThickness": Thickness thickness = StringToThickness(StyleSetter.InnerText); Setter borderThickness = new Setter(DataGridRow.BorderThicknessProperty, thickness); styleSetters.Add(borderThickness); break; case "IsCellSelected": Setter isCellSelected = new Setter(DataGridAttachedProperties.IsCellSelectedProperty, (StyleSetter.InnerText == "True" ? true : false)); DependencyPropertyDescriptor descriptor = DependencyPropertyDescriptor.FromName( "IsCellSelected", typeof(DataGridAttachedProperties), typeof(DataGridRow)); isCellSelected.Property = descriptor.DependencyProperty; styleSetters.Add(isCellSelected); break; } }