How to change an image position programatically without SetLeft?












0















I have searched before and I thought Canvas.SetLeft(image, double) would be the answer but it ain't doing anything



myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:UsersaluDesktopcaballos_jpgserie_22.jpg", UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
imgCb01.Source = myBitmapImage;
Canvas.SetLeft(imgCb01, 152d);//This aint working
Canvas.SetTop(imgCb01, 285.0);//This aint working
Thickness margin = imgCb01.Margin;//I thought this lines would move my image
margin.Left = (imgCb01.Margin.Left) + 5;//slightly to the right
imgCb01.Margin = margin;//and they do but they are hiding (TT-TT) ...


So I have this code, neither SetLeft nor SetTop work, and I thought I could do the trick modifying the margin but then the image moves "forward" while the image control keeps its position so it looks like the image has just became invisible.










share|improve this question




















  • 1





    Did you put your imgCb01 into Canvas control? Canvas.SetTop is an attached property and do nothing if control is not inside Canvas control.

    – Access Denied
    Nov 23 '18 at 8:16













  • It's also weird how you build you user interface. People usually don't use absolute coordinates in WPF as in winforms, but use Grid, StackPanel and etc. to make a layout.

    – Access Denied
    Nov 23 '18 at 8:19













  • Yes it's inside the canvas Grid/Canvas/Image, yeah I "know"(Im new to wpf tho... :'D) the position numbers are just some weird random numbers so I could notice if the image was "moving"

    – Tenxu
    Nov 23 '18 at 8:25











  • Check out the following sample dotnetperls.com/canvas-wpf

    – Access Denied
    Nov 23 '18 at 8:30











  • As a note, Canvas.imgCb01.SetLeft(imgCb01, 152d); is nonsense. It should be Canvas.SetLeft(imgCb01, 152d); If that doesn't work, the Image element is not a child of a Canvas element. Note also that you don't need to call BeginInit and EndInit. BitmapImage has a constructor that takes an Uri argument: imgCb01.Source = new BitmapImage(new Uri(...));. Finally, you shouldn't be creating UI elements in code at all. Use DataTemplates. Start reading here: Data Templating Overview

    – Clemens
    Nov 23 '18 at 8:31


















0















I have searched before and I thought Canvas.SetLeft(image, double) would be the answer but it ain't doing anything



myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:UsersaluDesktopcaballos_jpgserie_22.jpg", UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
imgCb01.Source = myBitmapImage;
Canvas.SetLeft(imgCb01, 152d);//This aint working
Canvas.SetTop(imgCb01, 285.0);//This aint working
Thickness margin = imgCb01.Margin;//I thought this lines would move my image
margin.Left = (imgCb01.Margin.Left) + 5;//slightly to the right
imgCb01.Margin = margin;//and they do but they are hiding (TT-TT) ...


So I have this code, neither SetLeft nor SetTop work, and I thought I could do the trick modifying the margin but then the image moves "forward" while the image control keeps its position so it looks like the image has just became invisible.










share|improve this question




















  • 1





    Did you put your imgCb01 into Canvas control? Canvas.SetTop is an attached property and do nothing if control is not inside Canvas control.

    – Access Denied
    Nov 23 '18 at 8:16













  • It's also weird how you build you user interface. People usually don't use absolute coordinates in WPF as in winforms, but use Grid, StackPanel and etc. to make a layout.

    – Access Denied
    Nov 23 '18 at 8:19













  • Yes it's inside the canvas Grid/Canvas/Image, yeah I "know"(Im new to wpf tho... :'D) the position numbers are just some weird random numbers so I could notice if the image was "moving"

    – Tenxu
    Nov 23 '18 at 8:25











  • Check out the following sample dotnetperls.com/canvas-wpf

    – Access Denied
    Nov 23 '18 at 8:30











  • As a note, Canvas.imgCb01.SetLeft(imgCb01, 152d); is nonsense. It should be Canvas.SetLeft(imgCb01, 152d); If that doesn't work, the Image element is not a child of a Canvas element. Note also that you don't need to call BeginInit and EndInit. BitmapImage has a constructor that takes an Uri argument: imgCb01.Source = new BitmapImage(new Uri(...));. Finally, you shouldn't be creating UI elements in code at all. Use DataTemplates. Start reading here: Data Templating Overview

    – Clemens
    Nov 23 '18 at 8:31
















0












0








0








I have searched before and I thought Canvas.SetLeft(image, double) would be the answer but it ain't doing anything



myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:UsersaluDesktopcaballos_jpgserie_22.jpg", UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
imgCb01.Source = myBitmapImage;
Canvas.SetLeft(imgCb01, 152d);//This aint working
Canvas.SetTop(imgCb01, 285.0);//This aint working
Thickness margin = imgCb01.Margin;//I thought this lines would move my image
margin.Left = (imgCb01.Margin.Left) + 5;//slightly to the right
imgCb01.Margin = margin;//and they do but they are hiding (TT-TT) ...


So I have this code, neither SetLeft nor SetTop work, and I thought I could do the trick modifying the margin but then the image moves "forward" while the image control keeps its position so it looks like the image has just became invisible.










share|improve this question
















I have searched before and I thought Canvas.SetLeft(image, double) would be the answer but it ain't doing anything



myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:UsersaluDesktopcaballos_jpgserie_22.jpg", UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
imgCb01.Source = myBitmapImage;
Canvas.SetLeft(imgCb01, 152d);//This aint working
Canvas.SetTop(imgCb01, 285.0);//This aint working
Thickness margin = imgCb01.Margin;//I thought this lines would move my image
margin.Left = (imgCb01.Margin.Left) + 5;//slightly to the right
imgCb01.Margin = margin;//and they do but they are hiding (TT-TT) ...


So I have this code, neither SetLeft nor SetTop work, and I thought I could do the trick modifying the margin but then the image moves "forward" while the image control keeps its position so it looks like the image has just became invisible.







c# .net wpf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 8:49







Tenxu

















asked Nov 23 '18 at 7:54









TenxuTenxu

13




13








  • 1





    Did you put your imgCb01 into Canvas control? Canvas.SetTop is an attached property and do nothing if control is not inside Canvas control.

    – Access Denied
    Nov 23 '18 at 8:16













  • It's also weird how you build you user interface. People usually don't use absolute coordinates in WPF as in winforms, but use Grid, StackPanel and etc. to make a layout.

    – Access Denied
    Nov 23 '18 at 8:19













  • Yes it's inside the canvas Grid/Canvas/Image, yeah I "know"(Im new to wpf tho... :'D) the position numbers are just some weird random numbers so I could notice if the image was "moving"

    – Tenxu
    Nov 23 '18 at 8:25











  • Check out the following sample dotnetperls.com/canvas-wpf

    – Access Denied
    Nov 23 '18 at 8:30











  • As a note, Canvas.imgCb01.SetLeft(imgCb01, 152d); is nonsense. It should be Canvas.SetLeft(imgCb01, 152d); If that doesn't work, the Image element is not a child of a Canvas element. Note also that you don't need to call BeginInit and EndInit. BitmapImage has a constructor that takes an Uri argument: imgCb01.Source = new BitmapImage(new Uri(...));. Finally, you shouldn't be creating UI elements in code at all. Use DataTemplates. Start reading here: Data Templating Overview

    – Clemens
    Nov 23 '18 at 8:31
















  • 1





    Did you put your imgCb01 into Canvas control? Canvas.SetTop is an attached property and do nothing if control is not inside Canvas control.

    – Access Denied
    Nov 23 '18 at 8:16













  • It's also weird how you build you user interface. People usually don't use absolute coordinates in WPF as in winforms, but use Grid, StackPanel and etc. to make a layout.

    – Access Denied
    Nov 23 '18 at 8:19













  • Yes it's inside the canvas Grid/Canvas/Image, yeah I "know"(Im new to wpf tho... :'D) the position numbers are just some weird random numbers so I could notice if the image was "moving"

    – Tenxu
    Nov 23 '18 at 8:25











  • Check out the following sample dotnetperls.com/canvas-wpf

    – Access Denied
    Nov 23 '18 at 8:30











  • As a note, Canvas.imgCb01.SetLeft(imgCb01, 152d); is nonsense. It should be Canvas.SetLeft(imgCb01, 152d); If that doesn't work, the Image element is not a child of a Canvas element. Note also that you don't need to call BeginInit and EndInit. BitmapImage has a constructor that takes an Uri argument: imgCb01.Source = new BitmapImage(new Uri(...));. Finally, you shouldn't be creating UI elements in code at all. Use DataTemplates. Start reading here: Data Templating Overview

    – Clemens
    Nov 23 '18 at 8:31










1




1





Did you put your imgCb01 into Canvas control? Canvas.SetTop is an attached property and do nothing if control is not inside Canvas control.

– Access Denied
Nov 23 '18 at 8:16







Did you put your imgCb01 into Canvas control? Canvas.SetTop is an attached property and do nothing if control is not inside Canvas control.

– Access Denied
Nov 23 '18 at 8:16















It's also weird how you build you user interface. People usually don't use absolute coordinates in WPF as in winforms, but use Grid, StackPanel and etc. to make a layout.

– Access Denied
Nov 23 '18 at 8:19







It's also weird how you build you user interface. People usually don't use absolute coordinates in WPF as in winforms, but use Grid, StackPanel and etc. to make a layout.

– Access Denied
Nov 23 '18 at 8:19















Yes it's inside the canvas Grid/Canvas/Image, yeah I "know"(Im new to wpf tho... :'D) the position numbers are just some weird random numbers so I could notice if the image was "moving"

– Tenxu
Nov 23 '18 at 8:25





Yes it's inside the canvas Grid/Canvas/Image, yeah I "know"(Im new to wpf tho... :'D) the position numbers are just some weird random numbers so I could notice if the image was "moving"

– Tenxu
Nov 23 '18 at 8:25













Check out the following sample dotnetperls.com/canvas-wpf

– Access Denied
Nov 23 '18 at 8:30





Check out the following sample dotnetperls.com/canvas-wpf

– Access Denied
Nov 23 '18 at 8:30













As a note, Canvas.imgCb01.SetLeft(imgCb01, 152d); is nonsense. It should be Canvas.SetLeft(imgCb01, 152d); If that doesn't work, the Image element is not a child of a Canvas element. Note also that you don't need to call BeginInit and EndInit. BitmapImage has a constructor that takes an Uri argument: imgCb01.Source = new BitmapImage(new Uri(...));. Finally, you shouldn't be creating UI elements in code at all. Use DataTemplates. Start reading here: Data Templating Overview

– Clemens
Nov 23 '18 at 8:31







As a note, Canvas.imgCb01.SetLeft(imgCb01, 152d); is nonsense. It should be Canvas.SetLeft(imgCb01, 152d); If that doesn't work, the Image element is not a child of a Canvas element. Note also that you don't need to call BeginInit and EndInit. BitmapImage has a constructor that takes an Uri argument: imgCb01.Source = new BitmapImage(new Uri(...));. Finally, you shouldn't be creating UI elements in code at all. Use DataTemplates. Start reading here: Data Templating Overview

– Clemens
Nov 23 '18 at 8:31














1 Answer
1






active

oldest

votes


















0














Well I think it was just some weird random bug from Microsoft Visual Studio, I just started again in other PC copying the XAML and it just worked fine... sorry to bother you :')






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%2f53442630%2fhow-to-change-an-image-position-programatically-without-setleft%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Well I think it was just some weird random bug from Microsoft Visual Studio, I just started again in other PC copying the XAML and it just worked fine... sorry to bother you :')






    share|improve this answer




























      0














      Well I think it was just some weird random bug from Microsoft Visual Studio, I just started again in other PC copying the XAML and it just worked fine... sorry to bother you :')






      share|improve this answer


























        0












        0








        0







        Well I think it was just some weird random bug from Microsoft Visual Studio, I just started again in other PC copying the XAML and it just worked fine... sorry to bother you :')






        share|improve this answer













        Well I think it was just some weird random bug from Microsoft Visual Studio, I just started again in other PC copying the XAML and it just worked fine... sorry to bother you :')







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 9:05









        TenxuTenxu

        13




        13
































            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%2f53442630%2fhow-to-change-an-image-position-programatically-without-setleft%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

            Costa Masnaga

            Fotorealismo

            Sidney Franklin