我正忙着使用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>
它绑定在我的应用程序的Models文件夹中的类中。 那个班看起来像这样; 公共类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 :(得分:0)
在return语句中而不是
android {
compileSdkVersion 26
buildToolsVersion '26.0.0-rc3'
defaultConfig {
targetSdkVersion 26
}
...
}
dependencies {
compile 'com.android.support:appcompat-v7:26.0.0-beta1'
}
// REQUIRED: Google's new Maven repo is required for the latest
// support library that is compatible with Android O
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
将其更改为
return location;
通过这种方式,您只会收到计数&gt; 0并仅显示那些。