【问题标题】:Bind count of pushpins on the Map to TextBlock将 Map 上的图钉计数绑定到 TextBlock
【发布时间】:2013-11-15 10:16:45
【问题描述】:

我在堆栈面板中有两个控件 - 地图和文本块。地图上的图钉集合动态变化。所以我需要 TextBlock 来显示图钉集合中的当前项目计数。 将 ItemsSource.Length 绑定到 TextBlock.Text 的正确方法是什么?有点像这样:

<maps:Map Name="MainMap">
     <toolkit:MapExtensions.Children>
         <toolkit:MapItemsControl Name="BusItems">
              <toolkit:MapItemsControl.ItemTemplate>
                   <DataTemplate>
                       <toolkit:Pushpin GeoCoordinate="{Binding Coordinates}" Content="{Binding Value}"/>
                   </DataTemplate>
              </toolkit:MapItemsControl.ItemTemplate>
         </toolkit:MapItemsControl>
     </toolkit:MapExtensions.Children>
</maps:Map>
<TextBlock Text="{Binding Items.Count, ElementName=BusItems}"></TextBlock>

【问题讨论】:

    标签: c# xaml binding windows-phone-8


    【解决方案1】:

    你不能绑定到 Items.Count,因为它是一个方法而不是一个属性,所以像这样创建一个暴露 Items.Count() 的属性:

    public int PushpinCount
    {
        get { return Items.Count(); }
    }
    

    并改为绑定到 PushpinCount。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多