[英]Referencing a WP7 border element in tap event
I have a WP7 app that is using bing maps and I have pushpins for multiple locations. 我有一个使用bing地图的WP7应用,并且我有多个位置的图钉。 On tapping the pushpin I have a tap event that displays a border with some text. 点击图钉时,我有一个点击事件,显示带有一些文本的边框。 To hide the text I'm using a tap event for the map control which sets the border visibility to collapsed: 为了隐藏文本,我使用了地图控件的tap事件,该控件将边框可见性设置为折叠:
private void map_Tap(object sender, GestureEventArgs e)
{
this.border.Visibility = Visibility.Collapsed;
}
Now if I am going to be using multiple borders and texts, I'm going to have to set the visibility multiple times like so: 现在,如果我要使用多个边框和文本,则必须多次设置可见性,如下所示:
this.border.Visibility = Visibility.Collapsed;
this.border2.Visibility = Visibility.Collapsed;
this.border3.Visibility = Visibility.Collapsed;
So I created a resource for the border in order to refer to just one border. 因此,我为边框创建了一个资源,以便仅引用一个边框。
<phone:PhoneApplicationPage.Resources>
<Style x:Key="BorderStyle" x:Name="border" TargetType="Border" >
<Setter Property="Background" Value="Black" />
</Style>
</phone:PhoneApplicationPage.Resources>
And I set the resource in the pushpin 然后在图钉中设置资源
<my:Pushpin.Content>
<Border Style="{StaticResource BorderStyle}" >
But now when I refer to the border in the map_Tap event I get a System.Windows.Style does not contain a definition for 'Visibility' because the border is no long referenced as a UIElement(at least that's how I'm understanding this). 但是现在当我在map_Tap事件中引用边框时,我得到一个System.Windows.Style不包含“可见性”的定义,因为边框不再被引用为UIElement(至少这就是我所理解的方式) 。 How can a make a style for the border element and still reference it as an element? 边框元素如何制作样式并仍将其引用为元素?
I would like to suggest you this approach and this might help you for some other tasks too. 我想向您推荐这种方法,这也可能会帮助您完成其他一些任务。
You use a list
of type border
and add all the border
elements into it. 您使用类型为border
的list
,并将所有border
元素添加到其中。 Now whenever you want to manipulate all the elements you can have a foreach
loop and access any property you would like example item.Visibility
and you can manipulate it as you like. 现在,只要您想操纵所有元素,就可以有一个foreach
循环并访问您想要示例item.Visibility
任何属性。 item.Visibility
,您可以根据需要进行操纵。 This will even help you sort them out so that you can manipulate any specific border. 这甚至可以帮助您整理它们,以便您可以操纵任何特定的边界。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.