The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
c# create dynamic HubSection RRS feed

  • Question

  • hi to all.

    I used to have a hub witch I create with xaml.

    Till now I can create the hubsection, but I am missing the background (suppose to be a Bitmap Image), the Grid, the Flyout, and the 2 textblocks

    my code so far:

                for (int i = 0; i < mychannels.channels.Count; i++)
                {
                    HubSection hubSection = new HubSection();
                    TextBlock headerTextBlock = new TextBlock();
                    headerTextBlock.Text = mychannels.channels[i].Name;
                    hubSection.Header = headerTextBlock;
                    hubSection.Padding = new Thickness(40, 30, 150, 44);
                    hubSection.DataContext = mychannels.channels[i].epg;
    
                    this.MainHub.Sections.Add(hubSection);
                }

    how can I do this with c# in a loop ?

    my xaml:

    <Hub Grid.Row="1" x:Name="MainHub">
                <HubSection x:Name="MyHub0" DataContext="{Binding}" >
                    <DataTemplate>
    
                        <ListView Name="myLst" Grid.Row="1" HorizontalAlignment="Center" ItemsSource="{Binding}" >
    
                            <ListView.ItemTemplate>
                                    <DataTemplate>
                                    <Grid Name="MyGrid" Height="150" Holding="Grid_Holding" DataContext="{Binding}">
    
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="0.3*" />
                                            <RowDefinition Height="0.7*" />
                                        </Grid.RowDefinitions>
    
                                        <FlyoutBase.AttachedFlyout>
                                            <Flyout x:Name="MyFlyout">
                                                <StackPanel Width="200">
                                                    <TextBlock Text="Λεπτά για την υπενθύμιση" FontSize="16" />
                                                    <TextBox x:Name="MinutesValueTextBox" Text="60" InputScope="Number" />
                                                    <Button Content="Προσθήκη υπενθύμισης" HorizontalAlignment="Center" FontSize="16"  Click="AddReminder_Click" />
                                                </StackPanel>
                                            </Flyout>
                                        </FlyoutBase.AttachedFlyout>
    
                                        <TextBlock Text="{Binding Time}" Grid.Row="0"   
                                                    FontSize="20" Margin="20,0,0,0"
                                                    TextWrapping="NoWrap" 
                                                    HorizontalAlignment="Left" />
    
                                        <TextBlock Text="{Binding Description}" Grid.Row="1" 
                                                    FontSize="24" Margin="20,0,0,0" 
                                                    TextWrapping="WrapWholeWords"
                                                    HorizontalAlignment="Left" />
                                    </Grid>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
    
                    </DataTemplate>
                </HubSection>
    
    ...
    
    </Hub>

    Thursday, April 16, 2015 8:52 PM

Answers

  • for anybody who is interesting, I did it.

    I move everything to the page resources and I access it from the ContentTemplate


    <Page.Resources>
    
            <DataTemplate x:Key="myDataTemplate">
                <ListView Name="myLst" Grid.Row="1" HorizontalAlignment="Center" ItemsSource="{Binding}" > 
                        <ListView.ItemTemplate>
                            <DataTemplate>
                            <Grid Name="MyGrid" Grid.Row="1" Height="150" Holding="Grid_Holding" DataContext="{Binding}">
                                <Grid.RowDefinitions>
                                        <RowDefinition Height="0.3*" />
                                        <RowDefinition Height="0.7*" />
                                    </Grid.RowDefinitions>
    
                                    <FlyoutBase.AttachedFlyout>
                                        <Flyout x:Name="MyFlyout">
                                            <StackPanel Width="200">
                                                <TextBlock Text="Λεπτά για την υπενθύμιση" FontSize="16" />
                                                <TextBox x:Name="MinutesValueTextBox" Text="60" InputScope="Number" />
                                                <Button Content="Προσθήκη υπενθύμισης" HorizontalAlignment="Center" FontSize="16"  Click="AddReminder_Click" />
                                            </StackPanel>
                                        </Flyout>
                                    </FlyoutBase.AttachedFlyout>
    
                                    <TextBlock Text="{Binding Time}" Grid.Row="0"   
                                                    FontSize="20" Margin="20,0,0,0"
                                                    TextWrapping="NoWrap" 
                                                    HorizontalAlignment="Left" />
    
                                    <TextBlock Text="{Binding Description}" Grid.Row="1" 
                                                    FontSize="24" Margin="20,0,0,0" 
                                                    TextWrapping="WrapWholeWords"
                                                    HorizontalAlignment="Left" />
                                </Grid>
                        </DataTemplate>
                        </ListView.ItemTemplate>
                </ListView>
            </DataTemplate>             
            
        </Page.Resources>

    Monday, April 20, 2015 3:54 PM

All replies

  • Hello,

    Can you post all the full code in here? For example the code for mychannels.


    I sale myself ONLY half CNY!


    Friday, April 17, 2015 1:50 PM
  • myChannel is a class type of:

        public class Channel
        {
            public String Date { get; set; }
            public List<Channels> channels { get; set; }
        }

        public class Channels
        {
            public string Name { get; set; }
            public string ImageUrl { get; set; }
            public List<epg> epg { get; set; }
        }

        public class epg
        {
            public string Time { get; set; }
            public string Description { get; set; }
        }

    I want to show the Time and the Description in every hub

    Saturday, April 18, 2015 9:02 AM
  • anyone please?
    Sunday, April 19, 2015 12:35 PM
  • for anybody who is interesting, I did it.

    I move everything to the page resources and I access it from the ContentTemplate


    <Page.Resources>
    
            <DataTemplate x:Key="myDataTemplate">
                <ListView Name="myLst" Grid.Row="1" HorizontalAlignment="Center" ItemsSource="{Binding}" > 
                        <ListView.ItemTemplate>
                            <DataTemplate>
                            <Grid Name="MyGrid" Grid.Row="1" Height="150" Holding="Grid_Holding" DataContext="{Binding}">
                                <Grid.RowDefinitions>
                                        <RowDefinition Height="0.3*" />
                                        <RowDefinition Height="0.7*" />
                                    </Grid.RowDefinitions>
    
                                    <FlyoutBase.AttachedFlyout>
                                        <Flyout x:Name="MyFlyout">
                                            <StackPanel Width="200">
                                                <TextBlock Text="Λεπτά για την υπενθύμιση" FontSize="16" />
                                                <TextBox x:Name="MinutesValueTextBox" Text="60" InputScope="Number" />
                                                <Button Content="Προσθήκη υπενθύμισης" HorizontalAlignment="Center" FontSize="16"  Click="AddReminder_Click" />
                                            </StackPanel>
                                        </Flyout>
                                    </FlyoutBase.AttachedFlyout>
    
                                    <TextBlock Text="{Binding Time}" Grid.Row="0"   
                                                    FontSize="20" Margin="20,0,0,0"
                                                    TextWrapping="NoWrap" 
                                                    HorizontalAlignment="Left" />
    
                                    <TextBlock Text="{Binding Description}" Grid.Row="1" 
                                                    FontSize="24" Margin="20,0,0,0" 
                                                    TextWrapping="WrapWholeWords"
                                                    HorizontalAlignment="Left" />
                                </Grid>
                        </DataTemplate>
                        </ListView.ItemTemplate>
                </ListView>
            </DataTemplate>             
            
        </Page.Resources>

    Monday, April 20, 2015 3:54 PM