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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:36:36+00:00 2026-05-27T21:36:36+00:00

I have been looking for a simple way to allow a similar functionality to

  • 0

I have been looking for a simple way to allow a similar functionality to the built-in Image Viewer (Zooming in and out of an image with 2 fingers, pinch zoom / zoom out, and the floating effect, if someone gently pushes an image in one of the directions).

Initially I was trying to achieve it with the Image control, but It turned out to be extremely difficult.

I decided to go with the Webbrowser control, as it seemed to offer just what I need and it had a benefit of clipping it’s content to the parent container ( an Image control wouldn’t do that by default ).

I placed the Webbrowser control in the second Row of a 2-row parent Grid container (Its basically the default Page generated by Visual Studio)

<Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <toolkit:PerformanceProgressBar x:Name="ProgressBar" IsIndeterminate="True" />
            <phone:WebBrowser Visibility="Collapsed" x:Name="BrowserWindow" IsScriptEnabled="True" />
</Grid>

The C# code backing the View is this:

public partial class ItemDetailView : PhoneApplicationPage
{

public static string HtmlTemplate =
    @"<!doctype html>
      <html>
        <head>
        <meta name='viewport' content='initial-scale=0.1,minimum-scale=0.1,user-scalable=yes,width=480' />
        <title></title>
        <script type='text/javascript'>
        function imageLoadFailed() {{
            window.external.notify('ImageLoadFailed');
        }}
        </script>
        </head>
        <body style='margin:0; padding:0; width:100%; background-color: {0};'>
        <div style='margin:0 auto;'><img onerror='imageLoadFailed()' src='{1}' alt='' /></div>
        </body>
      </html>";


public ItemDetailView() {
    InitializeComponent();
    this.BrowserWindow.LoadCompleted += (s, e) => {
        this.ProgressBar.IsIndeterminate = false;
        this.BrowserWindow.Visibility = Visibility.Visible;
    };

    this.BrowserWindow.ScriptNotify += (s, e) => {
        if (e.Value == "ImageLoadFailed") {
            MessageBox.Show("Image failed to load");
        }
    };
}

public ItemDetailViewModel VM {
    get {
        return this.DataContext as ItemDetailViewModel
    }
}

public bool IsBackgroundBlack() {
    return Visibility.Visible == (Visibility)Resources["PhoneDarkThemeVisibility"];
}
protected override void OnNavigatedTo(NavigationEventArgs e) {
    base.OnNavigatedTo(e);
    App app = App.Current as App;
    this.VM.Item = app.CurrentItem;

    string css = "";
    if (this.IsBackgroundBlack()) {
        css = "black";
    }
    else {
        css = "white";
    }
    this.BrowserWindow.NavigateToString(string.Format(ItemDetailView.HtmlTemplate, css, app.CurrentItem.Url));

}

}

As you may see, I set the width to 480 in the Viewport meta tag. This is the only value that is close enough to center the image so it appears naturally as if placed in an Image control (it fits within the width of the phones screen and is scaled appropriately)

I tried to set the viewport meta tag width property to ‘device-width’, but with this setting, the image reaches beyond the phones screen width upon initial load.

I also have noticed that with width set to 480, if a user taps on the Web browser for the first time, the browser centers the image a little bit, so 480 is not a perfect value. I am also concerned that this may not be the greatest solution given multiple screen sizes of other devices.

I am curious, if there is a cross-device way to center the image in the web browser control.

Reference Image:

enter image description here

  • Left Image – What I want, and what it more or less looks like with Viewport meta tag’s width=480 (Entire image is seen)
  • Right Image – What it looks like with Viewport meta tag’s width=device-width;
    (A single tap is needed to zoom out and position it in the center like the left image)
  • 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-27T21:36:36+00:00Added an answer on May 27, 2026 at 9:36 pm

    It appears that there is no need for setting the meta tag at all (it just caused trouble in my case)

    the html template:

    <!doctype html>
                  <html>
                    <head>
                    <title></title>
                    <script type='text/javascript'>
                    function imageLoadFailed() {
                        window.external.notify('ImageLoadFailed');
                    }
                    </script>
                    </head>
                    <body style='background-color: {0};'>
                    <img width='100%' onerror='imageLoadFailed()' src='{1}' alt='' /></div>
                    </body>
                  </html>
    

    does the trick

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

Sidebar

Related Questions

I've been looking for a simple regex for URLs, does anybody have one handy
I've been looking all over for a simple example of how to have an
Introduction : Hello Everyone, I have been looking for days for a way to
I have been looking for a easy way to add borders to custom made
I have been looking for some simple examples of how to best use Castle
I have been looking for a way to set up what I thought would
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been looking into IKVMing Apache's FOP project to use with our .NET
We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance
I have been looking at metrics for coupling and also look at DSM .

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.