Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:04:13+00:00 2026-06-07T11:04:13+00:00

I am adding to a CavnasObject (Size 0, 0) a Line Element in Code.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:04:15+00:00Added an answer on June 7, 2026 at 11:04 am

    Ok after testing I figured out that your XAML might be the problem. Your Canvas is created in the Visual Tree behind the DataGrid so any Line will be shown behind the DataGrid. And since you use a StackPanel as root element I’m not sure where your Line will end up. To fix the issue rewrite your XAML to something similar to this:

    <Grid Grid.Column="1">
      <DataGrid/>
      <Canvas x:Name="lineCanvas"/>
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Adding different plugins, scripts and other jquery the code gets pretty messy. What is
When adding new properties to classes, I find myself typing the same things over
Adding Exceptional Handling is a good practise, but I have a doubt, In our
Adding the row one by one in the button click.. (i tried but its
Adding strings localization files in iPhone bundle is very simple and perfectly fine but
Adding files to .hgignore will prevent them from being tracked. But we have some
Adding support for Unicode passwords it an important feature that should not be ignored
Adding clear: left, clear: right, or clear:both to an element would create an extra
Adding runat=server is not rendering my server tags <%...%> I have a masterpage with
Adding Multiple series to the ComboChart with different graph types is straightforward, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.