8,757
社区成员
发帖
与我相关
我的任务
分享
我在初始化BingMap之后,自定义了菜单功能,如下:
public Top()
{
InitializeComponent();
map.MapForeground.TemplateApplied += new EventHandler(MapForeground_TemplateApplied);
}
void MapForeground_TemplateApplied(object sender, EventArgs e)
{
map.MapForeground.NavigationBar.TemplateApplied += new EventHandler(NavigationBar_TemplateApplied);
}
void NavigationBar_TemplateApplied(object sender, EventArgs e)
{
NavigationBar navBar = map.MapForeground.NavigationBar;
Button btnTest = new Button();
btnTest.Content = "Click";
navBar.HorizontalPanel.Children.Add(btnTest);
if (navBar.HorizontalPanel != null)
{
navBar.HorizontalPanel.Children.Clear();
CommandToggleButton btnCQ = new CommandToggleButton(new CustomCommand("城区"), "城区", "城区");
navBar.HorizontalPanel.Children.Add(btnCQ);
}
public class CustomCommand : NavigationBarCommandBase
{
public string CityName { get; set; }
public CustomCommand(string name)
{
this.CityName = name;
}
public override void Execute(Microsoft.Maps.MapControl.Core.MapBase map)
{
double longitude = 0d;
double latitude = 0d;
switch (CityName)
{
case "城区":
longitude = double.Parse("29.35");
latitude = double.Parse("106.33");
map.ZoomLevel = 10;
DataBind(参数)
---始终就无法绑定我的页面中的DataGrid了,因为它是当前页面的新类,基础类是 public partial class Top : UserControl
break;
map.Center = new Location(longitude, latitude);
NavigationBarCommandStatus status = this.GetStatus(map);
if (status == NavigationBarCommandStatus.Checked)
map.ScaleVisibility = Visibility.Collapsed;
else if (status == NavigationBarCommandStatus.Normal)
map.ScaleVisibility = Visibility.Visible;
}
public override NavigationBarCommandStatus GetStatus(MapBase map)
{
return base.GetStatus(map);
}
}
namespace PBSLPortal
{
public partial class Home : Page
{
public Home()
{
InitializeComponent();
MyMap.MapForeground.TemplateApplied += new EventHandler(MapForeground_TemplateApplied);
BindGrid("主城片区");
}
void MapForeground_TemplateApplied(object sender, EventArgs e)
{
MyMap.MapForeground.NavigationBar.TemplateApplied += new EventHandler(NavigationBar_TemplateApplied);
}
void NavigationBar_TemplateApplied(object sender, EventArgs e)
{
NavigationBar navBar = MyMap.MapForeground.NavigationBar;
//菜单导航位置
//navBar.Margin = new Thickness(220,0,0,0);
Button btnTest = new Button();
btnTest.Content = "Click";
navBar.HorizontalPanel.Children.Add(btnTest);
DataPager dp=new DataPager();
DataGrid gd=new DataGrid();
if (navBar.HorizontalPanel != null)
{
navBar.HorizontalPanel.Children.Clear();
CommandToggleButton btnCQ = new CommandToggleButton(new CustomCommand("城区", dp, gd), "城区", "城区");
navBar.HorizontalPanel.Children.Add(btnCQ);
}
}
public void BindGrid(string regionname)
{
if (regionname == null )
{
regionname = "主城片区";
}
else
{
client.GetBranchDataAsync(7, 0, regionname);
client.GetBranchDataCompleted +=
new EventHandler<GetPivotViewer.GetBranchDataCompletedEventArgs>(BranchDataBinder);
}
}
void BranchDataBinder(object sender, GetPivotViewer.GetBranchDataCompletedEventArgs e)
{
if (e.Error != null)
{ }
else
{
ObservableCollection<GetPivotViewer.BranchData> Branchist =
e.Result as ObservableCollection<GetPivotViewer.BranchData>;
string Region_Name = "";
List<string> valueList = new List<string>();
List<double> dboubleList = new List<double>();
for (int i = 0; i < Branchist.Count; i++)
{
Region_Name = Branchist[0].Region_Name.ToString();
GetPivotViewer.BranchData bd = Branchist[i];
valueList.Add(bd.Branch_Name);
dboubleList.Add(rd.Next(1435, 1883) / 10000.0 * 100);
}
//先绑定分页;
PagedCollectionView pcv = new PagedCollectionView(Branchist);
this.dpBranchdataGrid.Source = pcv;
this.BranchdataGrid.ItemsSource = pcv;
}
}
public class CustomCommand : NavigationBarCommandBase
{
public string CityName { get; set; }
public DataPager DP { get; set; }
public DataGrid DG { get; set; }
public CustomCommand(string name, DataPager dp, DataGrid dg)
{
this.CityName = name;
this.DP = dp;
this.DG = dg;
}
public override void Execute(Microsoft.Maps.MapControl.Core.MapBase map)
{
double longitude = 0d;
double latitude = 0d;
switch (CityName)
{
case "城区":
longitude = double.Parse("29.35");
latitude = double.Parse("106.33");
map.ZoomLevel = 10;
/*******************--此处绑定 Home() 中的 BindGrid(string regionname) 方法。*******************/
/*******************--此处绑定 Home() 中的 BindGrid(string regionname) 方法。*******************/
break;
}
map.Center = new Location(longitude, latitude);
NavigationBarCommandStatus status = this.GetStatus(map);
if (status == NavigationBarCommandStatus.Checked)
map.ScaleVisibility = Visibility.Collapsed;
else if (status == NavigationBarCommandStatus.Normal)
map.ScaleVisibility = Visibility.Visible;
}
}
}