Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy I can't bind a custom class to GridView as a group?
    primarykey
    data
    text
    <p>I'm trying to bind some items to my gridview but I also want to make them in groups. First of all, my xaml looks like this;</p> <pre><code>&lt;Page.Resources&gt; &lt;!-- TODO: Delete this line if the key AppName is declared in App.xaml --&gt; &lt;x:String x:Key="AppName"&gt;Header&lt;/x:String&gt; &lt;CollectionViewSource x:Name="itemsViewSource" IsSourceGrouped="True" Source="{Binding Items}"/&gt; &lt;DataTemplate x:Key="DataTemplate1"&gt; &lt;Grid HorizontalAlignment="Left" Width="168" Height="157"&gt; &lt;Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}"&gt; &lt;Image Source="{Binding Image}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/&gt; &lt;/Border&gt; &lt;StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}" Height="48"&gt; &lt;TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}" Height="59" Margin="16,0,7,0" FontSize="16" FontFamily="Andy"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/Page.Resources&gt; &lt;!-- This grid acts as a root panel for the page that defines two rows: * Row 0 contains the back button and page title * Row 1 contains the rest of the page layout --&gt; &lt;Grid x:Name="grd" Style="{StaticResource LayoutRootStyle}"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="140"/&gt; &lt;RowDefinition Height="*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;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}}" ItemTemplate="{StaticResource DataTemplate1}" SelectionMode="None" IsSwipeEnabled="false" IsItemClickEnabled="True" ItemClick="ItemView_ItemClick"&gt; &lt;GridView.Background&gt; &lt;ImageBrush ImageSource="Assets/bg4.jpg"/&gt; &lt;/GridView.Background&gt; &lt;GridView.GroupStyle&gt; &lt;GroupStyle&gt; &lt;GroupStyle.HeaderTemplate&gt; &lt;DataTemplate&gt; &lt;Grid Margin="1,0,0,6"&gt; &lt;Button AutomationProperties.Name="Group Title" Style="{StaticResource TextPrimaryButtonStyle}" Content="" /&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/GroupStyle.HeaderTemplate&gt; &lt;GroupStyle.Panel&gt; &lt;ItemsPanelTemplate&gt; &lt;VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/GroupStyle.Panel&gt; &lt;/GroupStyle&gt; &lt;/GridView.GroupStyle&gt; &lt;/GridView&gt; &lt;!-- Back button and page title --&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto"/&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/&gt; &lt;TextBlock x:Name="pageTitle" Grid.Column="1" Style="{StaticResource PageHeaderTextStyle}" FontFamily="Buxton Sketch" FontSize="60" Foreground="#DEFFFFFF" Margin="0,0,30,44"&gt; &lt;Run Foreground="#DE316191" Text="Merak"/&gt; &lt;Run FontSize="48" Text=" "/&gt; &lt;Run Foreground="#DEFDFDFD" Text="Edilen"/&gt; &lt;Run FontSize="48" Text=" "/&gt; &lt;Run Foreground="#DE3F6B97" Text="Şeyler"/&gt; &lt;/TextBlock&gt; &lt;/Grid&gt; &lt;VisualStateManager.VisualStateGroups&gt; &lt;!-- Visual states reflect the application's view state --&gt; &lt;VisualStateGroup x:Name="ApplicationViewStates"&gt; &lt;VisualState x:Name="FullScreenLandscape"/&gt; &lt;VisualState x:Name="Filled"/&gt; &lt;!-- The entire page respects the narrower 100-pixel margin convention for portrait --&gt; &lt;VisualState x:Name="FullScreenPortrait"&gt; &lt;Storyboard&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;!-- The back button and title have different styles when snapped --&gt; &lt;VisualState x:Name="Snapped"&gt; &lt;Storyboard&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; &lt;/Grid&gt; </code></pre> <p>With this I can create groups with this code;</p> <pre><code>public class Item { public string Title { get; set; } public string Description{ get; set; } public string Image { get; set; } } List&lt;List&lt;Item&gt;&gt; total = new List&lt;List&lt;Item&gt;&gt;(); List&lt;Item&gt; lst = new List&lt;Item&gt;(); public void AddGroups() { Item first= new Item(); first.Title = "asdf"; first.Description = "asdaf"; first.Image = "aswdfa"; lst.Add(first); total.Add(lst); } </code></pre> <p>With this code, I can add groups WITHOUT a header text but I need the header text, I can't do anything without it. So I was trying to make another custom class, and bind this new list to the gridview. I tried to create a class like this then bind a list of this class, but It doesn't work, shows a blank screen without any items in it;</p> <pre><code>public class grp { private List&lt;Item&gt; bilg; public grp(List&lt;Item&gt; bilg) { this.bilg = bilg; } } </code></pre> <p>The second class might be totally wrong tho I don't know. This is a Windows Store app and I'm using xaml and c#. Thanks for the helps.</p> <p>tl;dr I'm trying to make a gridview with groups with group names on top of them.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload