2017-06-14 24 views
-1

我忙於使用UWP應用程序。我有一個網格視圖,其中包含數據模板項目。它被設置如下:如何顯示/隱藏數據模板UWP

<GridView ItemsSource="{x:Bind location}"> 
<GridView.ItemTemplate> 
    <DataTemplate x:Name="columnTemplate" x:DataType="data:Locations"> 
    <StackPanel x:Name="columnStack"> 
    <Image Width="100" Source="{x:Bind locationColumnImage}"/> 
    <TextBlock FontSize ="16" Text ="{x:Bind numberOfBales}" 
    HorizontalAlignment="Center"/>       
    </StackPanel> 
    </DataTemplate> 
</GridView.ItemTemplate> 
</GridView> 

它是從模型文件夾中的類必將在我的應用程序.. 和類如下所示; 公共類的LocationManager

{ 
    public List<Locations> getLocations() 
    { 
     //represents db value of how many items in a particlar location 
     var baleCol = buildColumnList(); 
     var location = new List<Locations>(); 
     location.Add(new Locations { locationColumn = "A", locationColumnImage = "Assets/A.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("A")).Count() }); 
     location.Add(new Locations { locationColumn = "B", locationColumnImage = "Assets/B.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("B")).Count() }); 
     location.Add(new Locations { locationColumn = "C", locationColumnImage = "Assets/c.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("C")).Count() }); 
     location.Add(new Locations { locationColumn = "D", locationColumnImage = "Assets/D.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("D")).Count() }); 
     location.Add(new Locations { locationColumn = "E", locationColumnImage = "Assets/E.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("E")).Count() }); 
     location.Add(new Locations { locationColumn = "F", locationColumnImage = "Assets/F.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("F")).Count() }); 
     location.Add(new Locations { locationColumn = "G", locationColumnImage = "Assets/G.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("G")).Count() }); 
    return Locations; 
    } 
} 
} 

它基本上是在顯示圖像的信網格(a至g),並低於該字母數字(取決於多少/如果任何字母具有存儲在一個項目它的位置A,B,C ...)

我想知道的是,如果我不想顯示圖像下方有0的項目(如果沒有存儲在G中,則不顯示)我會那樣做嗎?

回答

0

在你return語句,而不是

return location; 

改變它

return location.Where(a => a.numberOfBales > 0); 

這樣你只會收到與計數> 0的那些項目,並只顯示那些。