如何在BingMaps for Silverlight中更改自定义Pushpin中元素的大小

3

我有一个包含椭圆形的自定义图钉,我想在C#代码中以编程方式更改其大小。我可以改变图钉的大小,但这会影响其在地图上的位置。

是否有一种方法可以直接通过渲染变换或直接更改其高度和宽度来直接处理椭圆形?

以下是XAML:

<map:Pushpin Location="51.4,-0.2" >
    <map:Pushpin.Template>
        <ControlTemplate>
            <Ellipse Width="15" Height="15" Fill="Red" Opacity="0.7" Stroke="Black" StrokeThickness="2.5">
                 <Ellipse.RenderTransform>   
                     <TranslateTransform X="0" Y="18" />
                 </Ellipse.RenderTransform>
             </Ellipse>
         </ControlTemplate>
     </map:Pushpin.Template>
</map:Pushpin>

以下是我目前正在使用的 C# 代码,用于更改 Pushpin 的大小(当前为随机数字):

private void MapItemsSizeChange()
{
    Random rnd = new Random();
    ScaleTransform pin_st = new ScaleTransform();

    if (mainMap != null)
    {
        foreach (UIElement UI in mainMap.Children)
        {
            if (UI is Pushpin)
            {
                var pin = UI as Pushpin;

                if (pin != null)
                {
                    double x = rnd.Next(5, 20);
                    x = x / 10;

                    pin_st.ScaleX = x;
                    pin_st.ScaleY = x;

                    UI.RenderTransform = pin_st;
                }
            }
        }
    }
}

感谢大家!
网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接