我正在尝试在Windows商店应用程序中绑定网格视图,因为我使用的是简单的代码,但我没有显示文本和图像,只显示了很少的块。
请帮助我,如何正确绑定数据。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//itemGridView.ItemsSource = myItems;
List<MyClass> lsst = new List<MyClass>();
lsst.Add(new MyClass("Assets/chat.png", "Title1", "Subtitle1"));
lsst.Add(new MyClass("Assets/chat.png", "Title1", "Subtitle1"));
lsst.Add(new MyClass("Assets/chat.png", "Title1", "Subtitle1"));
lsst.Add(new MyClass("Assets/chat.png", "Title1", "Subtitle1"));
lsst.Add(new MyClass("Assets/chat.png", "Title1", "Subtitle1"));
lsst.Add(new MyClass("Assets/chat.png", "Title1", "Subtitle1"));
itemGridView.ItemsSource = lsst;
}
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Items"
TabIndex="1"
Grid.RowSpan="2"
Padding="116,136,116,46"
ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
SelectionMode="None"
IsSwipeEnabled="false">
<GridView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left" Width="250" Height="250">
<Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}">
<Image Source="{Binding ImagePath}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
</Border>
<StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="{Binding Title}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" Height="60" Margin="15,0,15,0" FontWeight="SemiBold"/>
<TextBlock Text="{Binding Subtitle}" Foreground="{ThemeResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" TextWrapping="NoWrap" Margin="15,0,15,10" FontSize="12"/>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
答案 0 :(得分:0)
你设置了datacontext吗?并使用IPropertyChanged?
MainView函数中的:this.DataContext = this;
此外,实现IPropertyChanged接口。谷歌它,你会找到解决方案; - )