有个BingMap 自定义导航菜单问题,数据绑定问题

iloveyoujia 2011-10-30 02:03:56


我在初始化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);
}


}




如何解决在同一个命令空间里,新类绑定基础类的控件呢?比如:DataGrid,我直接在基础类绑定是没有问题的。非常感谢。
...全文
118 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zlp321002 2011-11-07
  • 打赏
  • 举报
回复
更改如下2出:
1、----------------------------------------------------------------
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);
}

===>
navBar.HorizontalPanel.Children.Clear();
CommandToggleButton btnCQ = new CommandToggleButton(new CustomCommand("主城", dpBranchdataGrid, BranchdataGrid), "主城", "主城");
navBar.HorizontalPanel.Children.Add(btnCQ);
-------------------------------------------

2、
/*******************--此处绑定 Home() 中的 BindGrid(string regionname) 方法。*******************/
/*******************--此处绑定 Home() 中的 BindGrid(string regionname) 方法。*******************/
BindData(参数);



实现方法:
public void BindData(string CityName)
{

GetPivotViewer.GetDataPivotViewerSoapClient client = new GetPivotViewer.GetDataPivotViewerSoapClient();
client.GetBranchDataAsync(7, 0, CityName);
client.GetBranchDataCompleted +=
new EventHandler<GetPivotViewer.GetBranchDataCompletedEventArgs>(BranchData);
}


实现绑定
void BranchData(object sender, GetPivotViewer.GetBranchDataCompletedEventArgs e)
{
Random rd = new Random();
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);
DP.Source = pcv;
DG.ItemsSource = pcv;

}
}
iloveyoujia 2011-11-03
  • 打赏
  • 举报
回复
楼上的朋友,不好意思,我没看懂你的留言,看看能不能帮我改改。谢谢。
不知道哪儿有问题,没绑定成功数据。。
基础绑定数据没有问题,点菜单操作的时候绑定不上去。




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

}










kakaniuren 2011-11-03
  • 打赏
  • 举报
回复
在新类中做一个控件属性,通过赋值的方式将基础类中的控件给到新类,从而就可以实现在新类中进行绑定操作.
iloveyoujia 2011-11-02
  • 打赏
  • 举报
回复
其实就是 DataBind(参数) 在基础类里面有

PagedCollectionView pcv = new PagedCollectionView(Branchist);
this.dpBranchdataGrid.Source = pcv;
this.BranchdataGrid.ItemsSource = pcv;


我在新类里面调用不到这个办法。报不能使用static的方法错误。。。。
jv9 2011-10-31
  • 打赏
  • 举报
回复
不是很明白你的问题,什么叫做新类帮顶基础类的控件?能详细解释一下么?

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧