问题描述
||
我是Silverlight的新手,因此也是Bing Map Control的新手。
这是我想要实现的目标
我有一个具有2个属性的viewmodel,看起来像这样...
public class Vm : INotifyPropertyChanged
{
private LocationCollection _locations;
public LocationCollection Locations
{
get { return _locations; }
set
{
_locations = value;
this.Notify(\"Locations\");
}
}
private Location _selectedLocation;
public Location SelectedLocation
{
get { return _selectedLocation; }
set
{
_selectedLocation = value;
this.Notify(\"SelectedLocation\");
}
}
protected virtual void Notify(string property)
{
if( null != this.PropertyChanged)
{
PropertyChangedEventArgs e = new PropertyChangedEventArgs(property);
this.PropertyChanged(this,e);
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
在我的XAML中,我有一个列表框和一个Bing Map控件。列表框绑定到位置(display成员现在是一个Latitude),并且地图控件具有一个MapsItemControl,它也绑定到Locations。
ListBox的SelectedItem绑定到SelectedLocation,地图的中心也绑定到SelectedLocation。所以xaml看起来像这样
<Grid x:Name=\"LayoutRoot\" Background=\"White\">
<Grid.RowDeFinitions>
<RowDeFinition Height=\"Auto\"/>
<RowDeFinition Height=\"Auto\"/>
</Grid.RowDeFinitions>
<ListBox ItemsSource=\"{Binding Path=Locations}\"
SelectedItem=\"{Binding Path=SelectedLocation,Mode=TwoWay}\"
displayMemberPath=\"Latitude\"
Grid.Row=\"0\"/>
<map:Map
Grid.Row=\"1\"
CredentialsProvider=\"Av2K1aKwZLPJRS-F_m1TGlFg2bPFVVDgMGbxfFp-1rdpUrwfQmiPSouaSHrHoK-j\"
Loaded=\"Map_Loaded\"
Center=\"{Binding Path=SelectedLocation,Mode=TwoWay}\"
ZoomLevel=\"17\">
<map:MapItemsControl x:Name=\"mapItemsControl\" ItemsSource=\"{Binding Path=Locations}\">
<map:MapItemsControl.ItemTemplate>
<DataTemplate>
<map:pushpin
Location=\"{Binding}\"
/>
</DataTemplate>
</map:MapItemsControl.ItemTemplate>
</map:MapItemsControl>
</map:Map>
</Grid>
当我在列表框中选择项目时,我可以看到地图的中心发生了变化。但是我也想在这种情况下更改图钉模板。假设我要显示图像而不是OOB图钉。我了解如何自定义图钉的概念,但是我无法在MapsItemControl中获得类似于在其他ItemsControl(如列表框等)中可以找到的任何选择状态。
有人可以帮我吗?
解决方法
您可以添加另一个仅绑定到SelectedLocation的MapItemsControl,并将另一个MapItemsControl绑定到SelectedSelected位置以外的所有位置。
这样,您可以为选定的模板和未选定的模板分别使用模板。