Search This Blog

Monday, October 24, 2016

Get Current Row WPF DataGrid

WPF > Controls > ItemsControl > DataGrid > ItemContainerGenerator > ContainerFromIndex

Returns the element corresponding to the item at the given index.

Example

How to get current row if row is not selected.

var index = dataGrid.Items.IndexOf(dataGrid.CurrentItem);


var row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);




Wednesday, October 19, 2016

Get rectangles from canvas WPF code behind

WPF > Controls > Layout > Canvas > Children


Example 

Get all rectangles from canvas.

private List<Rectangle> GetRectangles()
{
    return canvas.Children.OfType<Rectangle>().ToList();

}

Thursday, October 13, 2016

Round line WPF code behind

WPF > Line 


Line line = new Line
{
 Stroke = Brushes.Blue,
 StrokeThickness = 18,
 StrokeStartLineCap = PenLineCap.Round,
 StrokeEndLineCap = PenLineCap.Round,
 Height= 50,
 X1 = 50,
 X2 = 100,
 Y1 = 10,
 Y2 = 10
};
canvas.Children.Add(line);