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

  • Home
  • SEARCH
  • 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 8150667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:07:59+00:00 2026-06-06T15:07:59+00:00

I have an Image inside a Canvas : <Canvas> <Image HorizontalAlignment=Center VerticalAlignment=Center /> </Canvas>

  • 0

I have an Image inside a Canvas:

<Canvas>
    <Image HorizontalAlignment="Center" VerticalAlignment="Center" />
</Canvas>

And I want to display the Image always (even after a possible resizing) in the center of my Canvas, but in this way the image is draw in the Top-Left corner. How can I do?

  • 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-06T15:08:01+00:00Added an answer on June 6, 2026 at 3:08 pm

    The coolest thing of this aproach taht it would work if you change sizes of both image and canvas.
    Converter code:

    internal sealed class CenterConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            double canvasWidth = System.Convert.ToDouble(values[0]);
            double canvasHeight = System.Convert.ToDouble(values[1]);
            double controlWidth = System.Convert.ToDouble(values[2]);
            double controlHeight = System.Convert.ToDouble(values[3]);
            switch ((string)parameter)
            {
                case "top":
                    return (canvasHeight - controlHeight) / 2;
                case "bottom":
                    return (canvasHeight + controlHeight) / 2;
                case "left":
                    return (canvasWidth - controlWidth) / 2;
                case "right":
                    return (canvasWidth + controlWidth) / 2;
                default:
                    return 0;
            }
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    XAML, somewhere in resources:

        <local:CenterConverter x:Key="CenterConverter" />
    

    XAML:

    <Canvas x:Name="superCoolCanvas">
        <Image x:Name="superCoolImage" >
            <Canvas.Top>
                <MultiBinding Converter="{StaticResource CenterConverter}" ConverterParameter="top">
                    <Binding ElementName="superCoolCanvas" Path="ActualWidth" />
                    <Binding ElementName="superCoolCanvas" Path="ActualHeight" />
                    <Binding ElementName="superCoolImage" Path="ActualWidth" />
                    <Binding ElementName="superCoolImage" Path="ActualHeight" />
                </MultiBinding>
            </Canvas.Top>
            <Canvas.Left>
                <MultiBinding Converter="{StaticResource CenterConverter}" ConverterParameter="left">
                    <Binding ElementName="superCoolCanvas" Path="ActualWidth" />
                    <Binding ElementName="superCoolCanvas" Path="ActualHeight" />
                    <Binding ElementName="superCoolImage" Path="ActualWidth" />
                    <Binding ElementName="superCoolImage" Path="ActualHeight" />
                </MultiBinding>
            </Canvas.Left>
        </Image>
    </Canvas>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to spread an image inside html5 canvas.. like say I have
Placing an image inside a Span (here : HtmlGenericControl ) programmatically Want to have
I have some paths that are not inside any canvas, and I want to
I have a Canvas element with inside an image ( the canvas has the
simple question for you fellas. I have an image inside a Canvas, with a
I have a canvas with an image inside it. I'm looking to put rounded
i have a canvas and an image inside canvas.i need know the position of
The CollapsibleAccordion. I have two canvas inside the CollapsibleAccordion, and everything works fine, but
I have an Image nested inside a Canvas. <mx:Canvas> <mx:Image source=@Embed(source='assets/library.swf', symbol='Waves') /> </mx:Canvas>
I have an image inside a div. I want that image to be draggable

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.