locked
how do I assign an imagebrush to a polygon fill property? RRS feed

  • Question

  • I am trying to create a polygon in a grid at runtime and have it fill with an image. It just displays an empty polygon What am I doing wrong?

      Dim poly As New Polygon()
            Dim Point1 = New Point(0, 0)
            Dim Point2 = New Point(0, 100)
            Dim Point3 = New Point(100, 100)
            Dim Point4 = New Point(100, 0)
            poly.Points.Add(Point1)
            poly.Points.Add(Point2)
            poly.Points.Add(Point3)
            poly.Points.Add(Point4)
            poly.StrokeThickness = 4
            poly.Stroke = New SolidColorBrush(Windows.UI.Colors.White)
            poly.Visibility = Windows.UI.Xaml.Visibility.Visible
            poly.Margin = New Thickness(100, 100, 0, 0)
            Dim polybrush = New ImageBrush()
            polybrush.ImageSource = New BitmapImage(New Uri("Assets\Image.png"))
            poly.Fill = polybrush
            grdTest.Children.Add(poly)

    Sunday, December 1, 2013 6:50 AM

Answers

  • Hi,

    You should change your code like below:

      Dim poly As New Polygon()
             Dim Point1 = New Point(0, 0)
             Dim Point2 = New Point(0, 100)
             Dim Point3 = New Point(100, 100)
             Dim Point4 = New Point(100, 0)
             poly.Points.Add(Point1)
             poly.Points.Add(Point2)
             poly.Points.Add(Point3)
             poly.Points.Add(Point4)
             poly.StrokeThickness = 4
             poly.Stroke = New SolidColorBrush(Windows.UI.Colors.White)
             poly.Visibility = Windows.UI.Xaml.Visibility.Visible
             poly.Margin = New Thickness(100, 100, 0, 0)
             Dim polybrush = New ImageBrush()
             polybrush.ImageSource = New BitmapImage(New Uri("ms-appx:///Assets/Image.png"))
             poly.Fill = polybrush
             grdTest.Children.Add(poly) 

    You can refer to the Uri schemes to get more information:

    http://msdn.microsoft.com/en-us/library/windows/apps/jj655406.aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Monday, December 9, 2013 1:37 AM
    Monday, December 2, 2013 2:17 AM

All replies

  • Hi,

    You should change your code like below:

      Dim poly As New Polygon()
             Dim Point1 = New Point(0, 0)
             Dim Point2 = New Point(0, 100)
             Dim Point3 = New Point(100, 100)
             Dim Point4 = New Point(100, 0)
             poly.Points.Add(Point1)
             poly.Points.Add(Point2)
             poly.Points.Add(Point3)
             poly.Points.Add(Point4)
             poly.StrokeThickness = 4
             poly.Stroke = New SolidColorBrush(Windows.UI.Colors.White)
             poly.Visibility = Windows.UI.Xaml.Visibility.Visible
             poly.Margin = New Thickness(100, 100, 0, 0)
             Dim polybrush = New ImageBrush()
             polybrush.ImageSource = New BitmapImage(New Uri("ms-appx:///Assets/Image.png"))
             poly.Fill = polybrush
             grdTest.Children.Add(poly) 

    You can refer to the Uri schemes to get more information:

    http://msdn.microsoft.com/en-us/library/windows/apps/jj655406.aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Monday, December 9, 2013 1:37 AM
    Monday, December 2, 2013 2:17 AM
  • Thanks That did the trick!
    Tuesday, December 10, 2013 4:14 AM