Windows 8 数据绑定快照模式Windows 8
使用GridView,我绑定到可观察集合中的几个项。当我进入快照模式时,我的GridView无法加载任何数据,并且所有项目都不可单击。见附件截图。我的应用在左边,上面写着特色和收藏夹。这是我的密码:Windows 8 数据绑定快照模式Windows 8,windows-8,Windows 8,使用GridView,我绑定到可观察集合中的几个项。当我进入快照模式时,我的GridView无法加载任何数据,并且所有项目都不可单击。见附件截图。我的应用在左边,上面写着特色和收藏夹。这是我的密码: public sealed partial class RestaurantHomePage : MenuFinderWin8.Common.LayoutAwarePage { MenuFinderAppServiceClient serviceClient; RestaurantR
public sealed partial class RestaurantHomePage : MenuFinderWin8.Common.LayoutAwarePage
{
MenuFinderAppServiceClient serviceClient;
RestaurantRepository repository;
Geolocator _geolocator = null;
ObservableCollection<RestaurantLocation> items;
public RestaurantHomePage()
{
this.InitializeComponent();
if (!Network.IsNetwork())
{
return;
}
repository = new RestaurantRepository();
serviceClient = new MenuFinderAppServiceClient();
_geolocator = new Geolocator();
items = new ObservableCollection<RestaurantLocation>();
//BindData();
}
void btnAbout_Click(object sender, RoutedEventArgs e)
{
Flyout f = new Flyout();
LayoutRoot.Children.Add(f.HostPopup); // add this to some existing control in your view like the root visual
// remove the parenting during the Closed event on the Flyout
f.Closed += (s, a) =>
{
LayoutRoot.Children.Remove(f.HostPopup);
};
// Flyout is a ContentControl so set your content within it.
SupportUserControl userControl = new SupportUserControl();
userControl.UserControlFrame = this.Frame;
f.Content = userControl;
f.BorderBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 223, 58, 51));
f.Width = 200;
f.Height = 200;
f.Placement = PlacementMode.Top;
f.PlacementTarget = sender as Button; // this is an UI element (usually the sender)
f.IsOpen = true;
}
void btnSearch_Click(object sender, RoutedEventArgs e)
{
Flyout f = new Flyout();
LayoutRoot.Children.Add(f.HostPopup); // add this to some existing control in your view like the root visual
// remove the parenting during the Closed event on the Flyout
f.Closed += (s, a) =>
{
LayoutRoot.Children.Remove(f.HostPopup);
};
// Flyout is a ContentControl so set your content within it.
RestaurantSearchUserControl userControl = new RestaurantSearchUserControl();
userControl.UserControlFrame = this.Frame;
f.Content = userControl;
f.BorderBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 223, 58, 51));
f.Width = 600;
f.Height = 400;
f.Placement = PlacementMode.Top;
f.PlacementTarget = sender as Button; // this is an UI element (usually the sender)
f.IsOpen = true;
}
void btnViewFavorites_Click(object sender, RoutedEventArgs e)
{
App.DataMode = Mode.SavedRestaurant;
if (repository.GetGroupedRestaurantsFromDatabase().Count() == 0)
{
MessageDialog messageDialog = new MessageDialog("You have no saved restaurants.", "No Restaurants");
messageDialog.ShowAsync();
}
else
{
this.Frame.Navigate(typeof(RestaurantSearchDetails));
}
}
private async void BindData()
{
try
{
items = await serviceClient.GetSpecialRestaurantsAsync();
List<RestaurantLocation> myFavs = repository.GetRestaurantLocations();
foreach (var a in myFavs)
{
items.Add(a);
}
this.DefaultViewModel["Items"] = items;
}
catch (Exception)
{
MessageDialog messsageDialog = new MessageDialog("The MenuFinder service is unavailable at this time or you have lost your internet connection. If your internet is OK, please check back later.", "Unavailable");
messsageDialog.ShowAsync();
btnAbout.IsEnabled = false;
btnSearch.IsEnabled = false;
btnViewFavorites.IsEnabled = false;
}
myBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="navigationParameter">The parameter value passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
/// </param>
/// <param name="pageState">A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.</param>
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
BindData();
// TODO: Assign a bindable collection of items to this.DefaultViewModel["Items"]
}
private void itemGridView_ItemClick_1(object sender, ItemClickEventArgs e)
{
App.CurrentRestaurantLocation = e.ClickedItem as RestaurantLocation;
if (App.CurrentRestaurantLocation != null)
{
Order order = repository.AddOrder(DateTime.Now, string.Empty, App.CurrentRestaurantLocation.ID);
App.CurrentOrder = order;
App.DataMode = Mode.Menu;
this.Frame.Navigate(typeof(RootViewPage));
}
}
}
public sealed分部类餐厅主题页面:MenuFinderWin8.Common.LayoutAwarePage
{
MenuFinderAppServiceClient服务客户端;
餐厅存储库;
Geolocator\u Geolocator=null;
可观察的收集项目;
公共餐厅
{
this.InitializeComponent();
如果(!Network.IsNetwork())
{
返回;
}
repository=新餐厅存储库();
serviceClient=new MenuFinderAppServiceClient();
_geolocator=新的geolocator();
items=新的ObservableCollection();
//BindData();
}
void btnAbout_单击(对象发送者,路由目标e)
{
弹出型按钮f=新弹出型按钮();
LayoutRoot.Children.Add(f.HostPopup);//将其添加到视图中的某些现有控件中,如根可视控件
//在弹出按钮上的关闭事件期间删除父项
f、 闭合+=(s,a)=>
{
LayoutRoot.Children.Remove(f.HostPopup);
};
//弹出按钮是一个ContentControl,因此可以在其中设置内容。
SupportUserControl userControl=新的SupportUserControl();
userControl.UserControlFrame=此.Frame;
f、 内容=用户控制;
f、 BorderBrush=新的SolidColorBrush(Windows.UI.Color.FromArgb(255、223、58、51));
f、 宽度=200;
f、 高度=200;
f、 Placement=PlacementMode.Top;
f、 PlacementTarget=sender as Button;//这是一个UI元素(通常是发件人)
f、 IsOpen=真;
}
无效btnSearch_单击(对象发送者,路由目标e)
{
弹出型按钮f=新弹出型按钮();
LayoutRoot.Children.Add(f.HostPopup);//将其添加到视图中的某些现有控件中,如根可视控件
//在弹出按钮上的关闭事件期间删除父项
f、 闭合+=(s,a)=>
{
LayoutRoot.Children.Remove(f.HostPopup);
};
//弹出按钮是一个ContentControl,因此可以在其中设置内容。
RestaurantSearchUserControl userControl=新的RestaurantSearchUserControl();
userControl.UserControlFrame=此.Frame;
f、 内容=用户控制;
f、 BorderBrush=新的SolidColorBrush(Windows.UI.Color.FromArgb(255、223、58、51));
f、 宽度=600;
f、 高度=400;
f、 Placement=PlacementMode.Top;
f、 PlacementTarget=sender as Button;//这是一个UI元素(通常是发件人)
f、 IsOpen=真;
}
无效btnViewFavorites\u单击(对象发送者,路由目标e)
{
App.DataMode=Mode.SavedRestaurant;
if(repository.getGroupedRestarantsFromDatabase().Count()==0)
{
MessageDialog=newmessagedialog(“您没有保存的餐厅。”,“没有餐厅”);
messageDialog.showsync();
}
其他的
{
this.Frame.Navigate(typeof(RestaurantSearchDetails));
}
}
私有异步void BindData()
{
尝试
{
items=等待serviceClient.GetSpecialRestarantsAsync();
List myFavs=repository.GetRestaurantLocations();
foreach(myFavs中的var a)
{
增加(a)项;
}
此.DefaultViewModel[“项”]=项;
}
捕获(例外)
{
MessageDialog MessageDialog=new MessageDialog(“MenuFinder服务目前不可用,或者您已失去internet连接。如果您的internet正常,请稍后再检查。”,“不可用”);
MessageDialog.ShowAsync();
btnAbout.IsEnabled=false;
btnSearch.IsEnabled=false;
btnViewFavorites.IsEnabled=false;
}
myBar.Visibility=Windows.UI.Xaml.Visibility.Collapsed;
}
///
///使用导航期间传递的内容填充页面。任何保存的状态也会
///从上一个会话重新创建页面时提供。
///
///传递给的参数值
///最初请求此页面时。
///
///此页在早期版本中保留的状态词典
///会话。第一次访问页面时,此值将为空。
受保护的覆盖无效加载状态(对象导航参数,字典页面状态)
{
BindData();
//TODO:为此分配可绑定的项集合。DefaultViewModel[“项”]
}
私有void itemGridView\u ItemClick\u 1(对象发送者,ItemClickEventArgs e)
{
App.CurrentRestaurantLocation=e.单击编辑项作为RestaurantLocation;
如果(App.CurrentRestaurantLocation!=null)
{
Order Order=repository.AddOrder(DateTime.Now,string.Empty,App.CurrentRestaurantLocation.ID);
App.CurrentOrder=订单;
App.DataMode=Mode.Menu;
this.Frame.Navigate(typeof(RootViewPage));
}
}
}
切换到快照视图时,gridView将隐藏,并显示一个ListView。您可以通过检查处理XAML中从一个到另一个的可视状态管理器来看到这一点
因此,解决方案是:通过绑定到适当的属性,从ListView中调整ItemTemplate,就像使用GridView一样;您可能还需要更改字体的前景色。此外,您还希望在ListView中包含IsItemClickEnabled和ItemClick(或SelectionMode和SelectionChanged)。能否显示您的代码?