积极答复者
GridView 怎么灰化某一项

问题
全部回复
-
int n = myGridView->Items->Size; for (int i = 0; i < n; i++) { HomeData^ h = safe_cast<HomeData^>(myGridView->Items->GetAt(i)); if (h->title->Equals("空")) { GridViewItem^ item = safe_cast<GridViewItem^>(myGridView->Items->GetAt(i)); //这里一直崩溃怎么办? item->IsEnabled=false; } }
First-chance exception at 0x77254B32 in Win8.exe: Microsoft C++ exception: Platform::InvalidCastException ^ at memory location 0x032DCF84. HRESULT:0x80004002 不支持此接口
WinRT 信息:不支持此接口大家还有没有好方法?
-
Hi,
一楼的方法是不行的,而且你这么写肯定会崩溃,因为IsEnableed属性是GridViewItem的属性。
向GridView添充Object用来显示的时候,无论使用绑定还是手动添加都会自动生成GridViewItem用来装载数据,但是我们从Item中却取不到这个,因此如果你想改变所有的可以用GridView.ItemContainerStyle来改变,只想改变一个可以用VisualTreeHelper取到特定的GridViewItem(这个应该很容易做到,有GetParent()方法)之后再改变IsEnabled即可,你可以看看这个参考中这段话:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.gridviewitem.aspx
The GridViewItem class provides the container for items displayed in a GridView control. You populate the GridView by adding objects directly to its Items collection or by binding its ItemsSource property to a data source. When items are added to the GridView, a GridViewItem container is created automatically for each item in the collection.
You can specify the look of the GridViewItem by setting the GridView's ItemContainerStyle property to a Style with aTargetType of GridViewItem.
Aaron
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
你这个方法是检测 ItemsPanel 来取得单个的项吗
<ItemsPanelTemplate x:Key="DetailStoreFrontGridItemsPanelTemplateEx"> <WrapGrid x:Name="SeqisEnable" MaximumRowsOrColumns="1" VerticalChildrenAlignment="Top" HorizontalChildrenAlignment="Left" Margin="0,0,30,0" Orientation="Vertical"/> </ItemsPanelTemplate>
WrapGrid^ DetailsPage::FindScrollView(DependencyObject^ parent,String^ name) //找“SeqisEnable” { int k = VisualTreeHelper::GetChildrenCount(parent); for (int i = 0; i < VisualTreeHelper::GetChildrenCount(parent); i++) { auto child = VisualTreeHelper::GetChild(parent, i); Platform::String^ controlName = safe_cast<String^> (child->GetValue(Control::NameProperty)); if (controlName == name) { WrapGrid^ findControl = safe_cast<WrapGrid^> (child); return findControl; } else { WrapGrid^ result = FindScrollView(child,name); if (result != nullptr) return result; } } return nullptr; }
WrapGrid^ h = FindScrollView(m_gridSeq,"SeqisEnable"); int xn = h ->Children->Size; GridViewItem^ s = safe_cast<GridViewItem^>(h->Children->GetAt(0)); s->IsEnabled=false;
这个方法必须在界面生成之后才有效果,在数据生成过程中,h->children->size 是 0;
我需要在界面生成的时候就决定isenabled属性。
- 已编辑 英明神武可爱 2013年1月8日 9:46
-
Hi,
你可以看看这个帖子的方法:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/c06d5b89-e3a8-41c9-8608-abbf2d1dc9f8
Aaron
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.