如何更改 BingMaps for Silverlight 中自定义图钉内元素的大小

发布于 2024-12-25 20:12:00 字数 1346 浏览 6 评论 0原文

我有一个包含椭圆的自定义图钉,我想在后面的 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#,它更改了图钉大小(当前为随机数):

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;
                }
            }
        }
    }
}

谢谢大家!

I have a custom pushpin which contains an Ellipse, and I would like to change its size programtically in the C# code behind. I am able to change the pushpin size, however, this affects its location on the map.

Is there a way for me to address the ellipse directly through a render transform or by directly changing its height and width?

Here is the 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>

Here is the C# I am using at present which changes the Pushpin sizes (currently to a random number):

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;
                }
            }
        }
    }
}

Thanks All!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文