how to use canvas.SetLeft on DateTime in wpfWhat is the correct way to create a single-instance WPF application?How do I use WPF bindings with RelativeSource?In WPF, what are the differences between the x:Name and Name attributes?WPF - ScreenSaver graphics performance improvementsHow do I exit a WPF application programmatically?Drawing lines and ellipses using ObservableCollection and ItemsControlWhy does a databinding for a Path's fill work but any binding for any of its child elements don't?How to draw simple shapes onto a WPF xaml-defined canvas programaticallyNew row in Binded DataGrid shows DatePicker as 01/01/0001How to WPF draw rectangle on top of image view dragged onto canvas

How do I find all files that end with a dot

Is it improper etiquette to ask your opponent what his/her rating is before the game?

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

What is Cash Advance APR?

Closed-form expression for certain product

Why electric field inside a cavity of a non-conducting sphere not zero?

Is the U.S. Code copyrighted by the Government?

How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?

Which one is correct as adjective “protruding” or “protruded”?

Not using 's' for he/she/it

Why should universal income be universal?

Can I sign legal documents with a smiley face?

What does chmod -u do?

Is it safe to use olive oil to clean the ear wax?

Why is it that I can sometimes guess the next note?

Is there a working SACD iso player for Ubuntu?

Why is so much work done on numerical verification of the Riemann Hypothesis?

If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?

If infinitesimal transformations commute why dont the generators of the Lorentz group commute?

Are the IPv6 address space and IPv4 address space completely disjoint?

Melting point of aspirin, contradicting sources

Create all possible words using a set or letters

Is there a name for this algorithm to calculate the concentration of a mixture of two solutions containing the same solute?

What was the exact wording from Ivanhoe of this advice on how to free yourself from slavery?



how to use canvas.SetLeft on DateTime in wpf


What is the correct way to create a single-instance WPF application?How do I use WPF bindings with RelativeSource?In WPF, what are the differences between the x:Name and Name attributes?WPF - ScreenSaver graphics performance improvementsHow do I exit a WPF application programmatically?Drawing lines and ellipses using ObservableCollection and ItemsControlWhy does a databinding for a Path's fill work but any binding for any of its child elements don't?How to draw simple shapes onto a WPF xaml-defined canvas programaticallyNew row in Binded DataGrid shows DatePicker as 01/01/0001How to WPF draw rectangle on top of image view dragged onto canvas













0















Sesaonallist is an ObservableCollection of type DataPoint.



I am trying to write each datapoint within the observable collection as an ellipse and draw it to a canvas. The problem is that X axis is of DateTime and I get the error




cannot convert DateTime to double




when I use Canvas.SetLeft(ellipse, Seasonallist[i].X);.



I don't want to use any third party libraries to do this, should i look into Converters?



Seasonallist = new ObservableCollection<DataPoint>();

if (Seasonallist != null)

for (int i = 0; i <= Seasonallist.Count - 1; i++)

Ellipse ellipse = new Ellipse();
ellipse.Width = 5;
ellipse.Height = 5;
ellipse.Fill = Brushes.Blue;
Canvas.SetLeft(ellipse, Seasonallist[i].X); <--error here
Canvas.SetTop(ellipse, Seasonallist.Y);
textCanvas.Children.Add(ellipse);



public class DataPoint

public DateTime X get; set;
public double Y get; set;










share|improve this question




























    0















    Sesaonallist is an ObservableCollection of type DataPoint.



    I am trying to write each datapoint within the observable collection as an ellipse and draw it to a canvas. The problem is that X axis is of DateTime and I get the error




    cannot convert DateTime to double




    when I use Canvas.SetLeft(ellipse, Seasonallist[i].X);.



    I don't want to use any third party libraries to do this, should i look into Converters?



    Seasonallist = new ObservableCollection<DataPoint>();

    if (Seasonallist != null)

    for (int i = 0; i <= Seasonallist.Count - 1; i++)

    Ellipse ellipse = new Ellipse();
    ellipse.Width = 5;
    ellipse.Height = 5;
    ellipse.Fill = Brushes.Blue;
    Canvas.SetLeft(ellipse, Seasonallist[i].X); <--error here
    Canvas.SetTop(ellipse, Seasonallist.Y);
    textCanvas.Children.Add(ellipse);



    public class DataPoint

    public DateTime X get; set;
    public double Y get; set;










    share|improve this question


























      0












      0








      0








      Sesaonallist is an ObservableCollection of type DataPoint.



      I am trying to write each datapoint within the observable collection as an ellipse and draw it to a canvas. The problem is that X axis is of DateTime and I get the error




      cannot convert DateTime to double




      when I use Canvas.SetLeft(ellipse, Seasonallist[i].X);.



      I don't want to use any third party libraries to do this, should i look into Converters?



      Seasonallist = new ObservableCollection<DataPoint>();

      if (Seasonallist != null)

      for (int i = 0; i <= Seasonallist.Count - 1; i++)

      Ellipse ellipse = new Ellipse();
      ellipse.Width = 5;
      ellipse.Height = 5;
      ellipse.Fill = Brushes.Blue;
      Canvas.SetLeft(ellipse, Seasonallist[i].X); <--error here
      Canvas.SetTop(ellipse, Seasonallist.Y);
      textCanvas.Children.Add(ellipse);



      public class DataPoint

      public DateTime X get; set;
      public double Y get; set;










      share|improve this question
















      Sesaonallist is an ObservableCollection of type DataPoint.



      I am trying to write each datapoint within the observable collection as an ellipse and draw it to a canvas. The problem is that X axis is of DateTime and I get the error




      cannot convert DateTime to double




      when I use Canvas.SetLeft(ellipse, Seasonallist[i].X);.



      I don't want to use any third party libraries to do this, should i look into Converters?



      Seasonallist = new ObservableCollection<DataPoint>();

      if (Seasonallist != null)

      for (int i = 0; i <= Seasonallist.Count - 1; i++)

      Ellipse ellipse = new Ellipse();
      ellipse.Width = 5;
      ellipse.Height = 5;
      ellipse.Fill = Brushes.Blue;
      Canvas.SetLeft(ellipse, Seasonallist[i].X); <--error here
      Canvas.SetTop(ellipse, Seasonallist.Y);
      textCanvas.Children.Add(ellipse);



      public class DataPoint

      public DateTime X get; set;
      public double Y get; set;







      wpf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 6:31









      RN92

      926724




      926724










      asked Mar 8 at 4:34









      masterinexmasterinex

      1622311




      1622311






















          2 Answers
          2






          active

          oldest

          votes


















          0














          you can try the Ticks Property of the DataTime.



          Canvas.SetLeft(ellipse, Convert.ToDouble(Seasonallist[i].X.Ticks));


          you have to find a good way to convert this big number into X Canvas coordination.






          share|improve this answer























          • okay, i have used the Ticks property, but it is giving a really huge number like Seasonallist[i].X.Ticks = 635241312000000000, can i just arbitrary divide that large number by some other number to reduce it to a smaller number ?

            – masterinex
            Mar 8 at 10:14


















          0














          Yes, you will need to use a converter but first you must determine the width of a time interval. This is best done using the ticks values so:



          TicksPerPixel is Display duration / Display Width



          You can then store this value and use formula DateTime.Ticks / TicksPerPixel to calculate the left property needed to draw it in the correct location.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056776%2fhow-to-use-canvas-setleft-on-datetime-in-wpf%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            you can try the Ticks Property of the DataTime.



            Canvas.SetLeft(ellipse, Convert.ToDouble(Seasonallist[i].X.Ticks));


            you have to find a good way to convert this big number into X Canvas coordination.






            share|improve this answer























            • okay, i have used the Ticks property, but it is giving a really huge number like Seasonallist[i].X.Ticks = 635241312000000000, can i just arbitrary divide that large number by some other number to reduce it to a smaller number ?

              – masterinex
              Mar 8 at 10:14















            0














            you can try the Ticks Property of the DataTime.



            Canvas.SetLeft(ellipse, Convert.ToDouble(Seasonallist[i].X.Ticks));


            you have to find a good way to convert this big number into X Canvas coordination.






            share|improve this answer























            • okay, i have used the Ticks property, but it is giving a really huge number like Seasonallist[i].X.Ticks = 635241312000000000, can i just arbitrary divide that large number by some other number to reduce it to a smaller number ?

              – masterinex
              Mar 8 at 10:14













            0












            0








            0







            you can try the Ticks Property of the DataTime.



            Canvas.SetLeft(ellipse, Convert.ToDouble(Seasonallist[i].X.Ticks));


            you have to find a good way to convert this big number into X Canvas coordination.






            share|improve this answer













            you can try the Ticks Property of the DataTime.



            Canvas.SetLeft(ellipse, Convert.ToDouble(Seasonallist[i].X.Ticks));


            you have to find a good way to convert this big number into X Canvas coordination.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 8 at 6:35









            Hakam FostokHakam Fostok

            5,61284469




            5,61284469












            • okay, i have used the Ticks property, but it is giving a really huge number like Seasonallist[i].X.Ticks = 635241312000000000, can i just arbitrary divide that large number by some other number to reduce it to a smaller number ?

              – masterinex
              Mar 8 at 10:14

















            • okay, i have used the Ticks property, but it is giving a really huge number like Seasonallist[i].X.Ticks = 635241312000000000, can i just arbitrary divide that large number by some other number to reduce it to a smaller number ?

              – masterinex
              Mar 8 at 10:14
















            okay, i have used the Ticks property, but it is giving a really huge number like Seasonallist[i].X.Ticks = 635241312000000000, can i just arbitrary divide that large number by some other number to reduce it to a smaller number ?

            – masterinex
            Mar 8 at 10:14





            okay, i have used the Ticks property, but it is giving a really huge number like Seasonallist[i].X.Ticks = 635241312000000000, can i just arbitrary divide that large number by some other number to reduce it to a smaller number ?

            – masterinex
            Mar 8 at 10:14













            0














            Yes, you will need to use a converter but first you must determine the width of a time interval. This is best done using the ticks values so:



            TicksPerPixel is Display duration / Display Width



            You can then store this value and use formula DateTime.Ticks / TicksPerPixel to calculate the left property needed to draw it in the correct location.






            share|improve this answer





























              0














              Yes, you will need to use a converter but first you must determine the width of a time interval. This is best done using the ticks values so:



              TicksPerPixel is Display duration / Display Width



              You can then store this value and use formula DateTime.Ticks / TicksPerPixel to calculate the left property needed to draw it in the correct location.






              share|improve this answer



























                0












                0








                0







                Yes, you will need to use a converter but first you must determine the width of a time interval. This is best done using the ticks values so:



                TicksPerPixel is Display duration / Display Width



                You can then store this value and use formula DateTime.Ticks / TicksPerPixel to calculate the left property needed to draw it in the correct location.






                share|improve this answer















                Yes, you will need to use a converter but first you must determine the width of a time interval. This is best done using the ticks values so:



                TicksPerPixel is Display duration / Display Width



                You can then store this value and use formula DateTime.Ticks / TicksPerPixel to calculate the left property needed to draw it in the correct location.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 8 at 10:24

























                answered Mar 8 at 10:18









                Matt NorrieMatt Norrie

                39610




                39610



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056776%2fhow-to-use-canvas-setleft-on-datetime-in-wpf%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme