Quiero trazar una línea en una cuadrícula WPF.Dibujar línea y moverla programáticamente
private void InitializeTestline()
{
testline = new Line();
grid.Children.Add(testline);
testline.X1 = 0;
testline.X2 = 1;
testline.Y1 = 0;
testline.Y2 = 1;
testline.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
testline.VerticalAlignment = System.Windows.VerticalAlignment.Top;
testline.Stroke = Brushes.Red;
testline.Stretch = Stretch.Fill;
testline.StrokeThickness = 2;
testline.Visibility = System.Windows.Visibility.Visible;
}
Se dibuja sin problemas. Pero ahora quiero agregar cuatro botones a la grilla (arriba, abajo, izquierda, derecha). Entonces, cuando presione uno de los botones, la línea se moverá en la dirección que elija.
private void MoveUp_Click(object sender, RoutedEventArgs e)
{
this.testline.Y1 += move;
this.testline.Y2 += move;
}
Esta es la función que quiero usar para esto, pero no funciona. Entonces, ¿cómo es posible mover esta línea?
En el extremo tengo una interfaz gráfica de usuario como un viejo terminal3270 y estos gui tiene un caret. las líneas deberían ser como una cruz (y ayudar a ver dónde está realmente la interpolación)
Lo siento, erróneamente pensé que estaba hablando de WPF DataGrid – Flot2011
Intente comentar //testline.Stretch = Stretch.Fill; – Klaus78
¡Gracias, funcionará bien ahora! ¿Sabes por qué no funciona con Stretch? – Pippl