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 6998047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:21:40+00:00 2026-05-27T20:21:40+00:00

I have a custom canvas in an application, which is not showing image, in

  • 0

I have a custom canvas in an application, which is not showing image, in XAML, i write:

<local:MyCanvas>
    <local:MyCanvas.LayoutTransform>
        <ScaleTransform x:Name="scale"  ScaleX="1" ScaleY="1" />
    </local:MyCanvas.LayoutTransform>
    <Image Source="C:\abc.jpg" />
</local:MyCanvas>

I have tried it on Canvas, and it works, but in the derived class, it doesn’t appear, but Visual Studio shows the outline meaning image has been added.

As an alternative, inside MyCanvas:Canvas class, i type:

Image img = new Image();
img.Width = 200;

BitmapImage myBitmapImage = new BitmapImage();

myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\abc.jpg");

myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();

img.Source = myBitmapImage;

this.Children.Add(img);

Still not visible. Any ideas?

  • 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-05-27T20:21:41+00:00Added an answer on May 27, 2026 at 8:21 pm

    I have been experimenting with different things and I have been able to add the image by enclosing it in a DrawingVisual, here is the code:

    private void addImage (DrawingContext dc)
    {
    BitmapImage bi = new BitmapImage();
    
    bi.BeginInit();
    bi.UriSource = new Uri(@"C:/abc.jpg");
    bi.EndInit();
    
    dc.DrawImage(bi, new Rect(new Point(0,0), new Point(200,200)));
    }
    

    And by then adding the DrawingVisual to the custom Canvas, here is the code:

    DrawingVisual abc = new DrawingVisual();
    DrawingContext dc = abc.RenderOpen ();
    addImage (dc)
    dc.Close();
    
    base.AddVisualChild(abc);
    base.addLogicalChild(abc);
    

    Using this method, the image is visible, and it is working fine.

    But why isn’t it adding to MyCanvas using the previous method?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom WPF Canvas, upon which I would like to show a
We have a custom canvas which has specialized nodes that behave a lot like
I have a custom DrawingCanvas which is inherited from Canvas. When I add a
I have a small WPF application, which has a Canvas and a Grid. I
I have custom classes that I currently instantiate within App.xaml as resources. I want
I'm looking into some XSS prevention in my Java application. I currently have custom
I have a Custom Canvas(DesignerCanvas), user can add some controls to this canvas. Before
I have created a UIScrollView (canvas.scrollview) and have a custom UIView (canvas) inside it.
I have a custom WPF control which consist of single TextBox <UserControl HorizontalAlignment=Left x:Class=WPFDiagramDesignerControl.Components.UcWBSBlock
The mainpage: MainPage.xaml <Canvas x:Name=LayoutRoot Background=White> </Canvas> MainPage.xaml.cs List<Usol> list = new List<Usol>(); for

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.