locked
Available Image size for SurfaceImageSource

    Question

  • I am trying to create an app that uses DirectX to display a 3D model in an image. I use the SurfaceImageSource as image source which I use as render target. This all is working fine when I set the Width and Height property of the image to a fixed number in Xaml.

    What I want to do now is divide the screen in a left and right part. The left side should display the image and the right side some properties. However I seem not be able to do that at the moment. I placed the image currently like:

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="308*"/>
          <ColumnDefinition Width="475*"/>
      </Grid.ColumnDefinitions>
      <StackPanel x:Name="ImagePlaceholder" Margin="20,20,0,20" Orientation="Vertical">
          <Image x:Name="ImageDice" Width="300" Height="600" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
      </StackPanel>
    </Grid>

    But now I want to get rid of the hard coded width and height property of the image and let the layout manager handle it. However, as I have no actual image the Source property hasn't been set. At runtime I see that (without the width & height property) both the stackpanel and image have a size of <0,0>.

    So, I wonder if I have to calculate the available size myself? Or is there a better way to do this? Thanks for any help. I'll happy to clarify wherever is needed.

    Jeroen

    Wednesday, November 21, 2012 7:49 AM

Answers

  • Hi,

    As far as I know, you can get the parent's width in the loaded event and then set the image Width as it.

    For example:

    <StackPanel x:Name="ImagePlaceholder" Margin="20,20,0,20" Orientation="Vertical" Grid.Column="0" HorizontalAlignment="Stretch" Loaded="ImagePlaceholder_Loaded_1">
                <WebView x:Name="WebView1" HorizontalAlignment="Left" Height="421" Margin="0,215,0,0" VerticalAlignment="Top" Width="838" Source="ms-appx-web:///test.html" Loaded="WebView_Loaded_1"/>
            </StackPanel>
            private void WebView_Loaded_1(object sender, RoutedEventArgs e)
            {
                double width = ImagePlaceholder.ActualWidth;
                WebView1.Width = width;
            }


    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Tuesday, November 27, 2012 7:01 AM
    • Marked as answer by Jesse Jiang Wednesday, December 05, 2012 2:32 AM
    Thursday, November 22, 2012 8:00 AM

All replies

  • Hi,

    As far as I know, you can get the parent's width in the loaded event and then set the image Width as it.

    For example:

    <StackPanel x:Name="ImagePlaceholder" Margin="20,20,0,20" Orientation="Vertical" Grid.Column="0" HorizontalAlignment="Stretch" Loaded="ImagePlaceholder_Loaded_1">
                <WebView x:Name="WebView1" HorizontalAlignment="Left" Height="421" Margin="0,215,0,0" VerticalAlignment="Top" Width="838" Source="ms-appx-web:///test.html" Loaded="WebView_Loaded_1"/>
            </StackPanel>
            private void WebView_Loaded_1(object sender, RoutedEventArgs e)
            {
                double width = ImagePlaceholder.ActualWidth;
                WebView1.Width = width;
            }


    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Tuesday, November 27, 2012 7:01 AM
    • Marked as answer by Jesse Jiang Wednesday, December 05, 2012 2:32 AM
    Thursday, November 22, 2012 8:00 AM
  • I hoped for that as well, but at runtime I noticed that the ImagePlaceHolder also had a Width of 0. I didn't try that in the OnLoaded though, but in SizeChanged event handler. Probably due to the empty image and nothing else in there occupying space.
    Thursday, November 22, 2012 9:52 AM
  • As far as I know, if you did not set the width, it will be 0 at runtime. Therefore, we use actualwidth to get width.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, November 27, 2012 7:01 AM