public void Revert_value_on_incorrect_input() { var waybill = new Waybill(new Address("тест"), new Supplier()); var line = new WaybillLine(waybill); line.RetailCost = 150; waybill.AddLine(line); WpfTestHelper.WithWindow2(async w => { var grid = new DataGrid2(); grid.IsReadOnly = false; grid.AutoGenerateColumns = false; grid.Columns.Add(new DataGridTextColumnEx { Binding = new Binding("Product") }); grid.Columns.Add(new DataGridTextColumnEx { Binding = new Binding("RetailCost") }); w.Content = grid; grid.ItemsSource = waybill.Lines; await w.WaitIdle(); var cell = grid.Descendants <DataGridCell>() .First(x => x.Column == grid.Columns[1] && x.DataContext == line); Assert.IsTrue(cell.Focus()); cell.SendKey(Key.F2); Assert.IsTrue(cell.IsEditing); var input = cell.Descendants <TextBox>().First(); input.SendText("asd"); grid.SendKey(Key.Down); Assert.IsFalse(cell.IsEditing); Assert.AreEqual(150, line.RetailCost); }); }
public void Style_fixture() { var offers = new List <Offer>(); offers.Add(new Offer(new Price("тест"), 100) { IsGrouped = true, BuyingMatrixType = BuyingMatrixStatus.Denied, }); WpfTestHelper.WithWindow2(async w => { var resources = new ResourceDictionary(); StyleHelper.Reset(); StyleHelper.BuildStyles(resources); var grid = new DataGrid2(); grid.AutoGenerateColumns = false; grid.Columns.Add(new DataGridTextColumn { Binding = new Binding("ProductSynonym") }); grid.Columns.Add(new DataGridTextColumn { Binding = new Binding("OrderCount") }); w.Content = grid; StyleHelper.ApplyStyles(typeof(Offer), grid, resources); grid.ItemsSource = offers; await w.WaitIdle(); var cells = grid.Descendants <DataGridCell>().ToArray(); Assert.That(cells.Length, Is.GreaterThan(0)); foreach (var cell in cells) { Assert.AreEqual("#FFFF0000", cell.Background.ToString(), ((TextBlock)cell.Content).Text); } }); }
public void Searchable_column() { WpfTestHelper.WithWindow2(async w => { var model = new SearchableModel(); var grid = new DataGrid2(); grid.DataContext = model; BindingOperations.SetBinding(grid, DataGrid.ItemsSourceProperty, new Binding("Items.Value")); BindingOperations.SetBinding(grid, SearchableDataGridColumn.SearchTermProperty, new Binding("Term.Value")); grid.AutoGenerateColumns = false; grid.Columns.Add(new SearchableDataGridColumn { Binding = new Binding("Item1"), HighlightStyle = new Style { Setters = { new Setter(TextElement.BackgroundProperty, Brushes.Red) } } }); w.Content = grid; await grid.WaitLoaded(); await w.WaitIdle(); model.Items.Value = Enumerable.Range(0, 49).Select(i => Tuple.Create(i.ToString())).ToList(); await w.WaitIdle(); model.Term.Value = "5"; model.Items.Value = Enumerable.Range(50, 100).Select(i => Tuple.Create(i.ToString())).ToList(); await w.WaitIdle(); var row = grid.Descendants <DataGridRow>().First(r => ((Tuple <String>)r.DataContext).Item1 == "50"); var text = row.Descendants <TextBlock>().First(); Assert.AreEqual("50", text.Text); var inlines = text.Inlines.OfType <Run>().ToArray(); Assert.AreEqual("5", inlines[0].Text); Assert.AreEqual("0", inlines[1].Text); }); }