I am adding to a CavnasObject (Size 0, 0) a Line Element in Code. But it gets not displayed. So I added the same line object in xaml with same Properties. In XAML it gets displayed but not in C#. Here is my code in C#:
Line line = new Line() { X1 = points[0].X, Y1 = points[0].Y, X2 = points[1].X, Y2 = points[1].Y, Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 4, Visibility = System.Windows.Visibility.Visible }; lineCanvas.Children.Add(line); The is not shown. And here is the line shown:
<StackPanel Grid.Column="1"> <Grid Height="0"> <Canvas Name="lineCanvas"> <Line X1="1" X2="240" Y1="33" Y2="33" StrokeThickness="4" Stroke="Red"/> </Canvas> </Grid> <DataGrid Name="dataGrid" Grid.Column="0" ItemsSource="{Binding ViewMap}" CanUserReorderColumns="False" CanUserSortColumns="False" AutoGenerateColumns="False" AllowDrop="True" DragEnter="dataGrid_DragEnter" Drop="dataGrid_Drop" SelectionUnit="FullRow" HeadersVisibility="Column" IsReadOnly="True" Panel.ZIndex="0" MouseDown="dataGrid_MouseDown"> <DataGrid.CellStyle># .... ... If you are yourself why Height=0 of the Grid. I am connecting datacells of a datagrid with lines. And to place to lines I am using a very small canvas object and i am simply displaying lines out of the canvas.
So does anyone has an idea whats wrong. The Values of the XAML are taken of the code.
points[0]andpoints[1]match the values you used in the Xaml?