locked
[XAML][8.1] Binding UserControl to HubSection RRS feed

  • Question

  • Hello,

    Having a bit of trouble binding my UserControls to Hub sections, does anyone have any help with regards to this.

    Any help would be greatly appreciated! :)

    <Hubx:Name="hubSection"Width="auto"Grid.Row="1"Margin="0,15,0,0">

    <HubSectionx:Name="Reservations"Header="reservations"FontSize="30"FontFamily="Segoe UI Light"FontWeight="SemiLight">

    <DataTemplate>

    <UserControl></UserControl>

    </DataTemplate>

    </HubSection>

    <HubSectionx:Name="rooms"Header="rooms"FontSize="30"FontFamily="Segoe UI Light"FontWeight="SemiLight"></HubSection>

    <HubSectionx:Name="equipment"Header="equipment"FontSize="30"FontFamily="Segoe UI Light"FontWeight="SemiLight"></HubSection>

    <HubSectionx:Name="catering"Header="catering"FontSize="30"FontFamily="Segoe UI Light"FontWeight="SemiLight"></HubSection>

    </Hub>

    Many thanks,

    Alan

    Friday, October 23, 2015 1:12 PM

Answers

  • >>Having a bit of trouble binding my UserControls to Hub sections, does anyone have any help with regards to this.

    What I understand from your code is that you want to invoke a usercontrol in a Hub section, if so, here I made an example( it contains a data binding in the user control):

    The user control:

    <Grid>
    
            <ListView ItemsSource="{Binding}">
    
                <ListView.ItemTemplate>
    
                    <DataTemplate>
    
                        <TextBlock Text="{Binding Text}"></TextBlock>
    
                    </DataTemplate>
    
                </ListView.ItemTemplate>
    
            </ListView>
    
        </Grid>
    

    The Hub control invoking the user control:

    <Hub x:Name="hubSection" Width="auto" Margin="0,15,0,0">
    
                <HubSection x:Name="Reservations" Header="reservations" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                    <DataTemplate>
    
                        <StackPanel>
    
                            <local:MyUserControl1 DataContext="{Binding}"/>
    
                        </StackPanel>
    
                    </DataTemplate>
    
                </HubSection>
    
                <HubSection x:Name="rooms" Header="rooms" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                </HubSection>
    
                <HubSection x:Name="equipment" Header="equipment" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                </HubSection>
    
                <HubSection x:Name="catering"  Header="catering" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                </HubSection>
    
            </Hub>
    

    Code for binding the source collection to the Hub section:

    public sealed partial class _06 : Page
    
        {
    
            public _06()
    
            {
    
                this.InitializeComponent();
    
                
    
                this.Reservations.DataContext = new List<Entity>() { new Entity() { Text = "asdsadwq" }, new Entity() { Text = "sadqdwqddqw" } };
    
            }
    
        }
    
    
        public class Entity
    
        {
    
            public string Text { get; set; }
    
    }
    

    If I do not understand correctly, please feel free to let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Fred Bao Monday, October 26, 2015 6:30 AM
    • Proposed as answer by Fred Bao Tuesday, November 3, 2015 7:15 AM
    • Unproposed as answer by alanmarklewis Tuesday, November 3, 2015 9:02 AM
    • Marked as answer by alanmarklewis Tuesday, November 3, 2015 9:03 AM
    Monday, October 26, 2015 6:29 AM

All replies

  • >>Having a bit of trouble binding my UserControls to Hub sections, does anyone have any help with regards to this.

    What I understand from your code is that you want to invoke a usercontrol in a Hub section, if so, here I made an example( it contains a data binding in the user control):

    The user control:

    <Grid>
    
            <ListView ItemsSource="{Binding}">
    
                <ListView.ItemTemplate>
    
                    <DataTemplate>
    
                        <TextBlock Text="{Binding Text}"></TextBlock>
    
                    </DataTemplate>
    
                </ListView.ItemTemplate>
    
            </ListView>
    
        </Grid>
    

    The Hub control invoking the user control:

    <Hub x:Name="hubSection" Width="auto" Margin="0,15,0,0">
    
                <HubSection x:Name="Reservations" Header="reservations" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                    <DataTemplate>
    
                        <StackPanel>
    
                            <local:MyUserControl1 DataContext="{Binding}"/>
    
                        </StackPanel>
    
                    </DataTemplate>
    
                </HubSection>
    
                <HubSection x:Name="rooms" Header="rooms" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                </HubSection>
    
                <HubSection x:Name="equipment" Header="equipment" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                </HubSection>
    
                <HubSection x:Name="catering"  Header="catering" FontSize="30" FontFamily="Segoe UI Light" FontWeight="SemiLight">
    
                </HubSection>
    
            </Hub>
    

    Code for binding the source collection to the Hub section:

    public sealed partial class _06 : Page
    
        {
    
            public _06()
    
            {
    
                this.InitializeComponent();
    
                
    
                this.Reservations.DataContext = new List<Entity>() { new Entity() { Text = "asdsadwq" }, new Entity() { Text = "sadqdwqddqw" } };
    
            }
    
        }
    
    
        public class Entity
    
        {
    
            public string Text { get; set; }
    
    }
    

    If I do not understand correctly, please feel free to let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Fred Bao Monday, October 26, 2015 6:30 AM
    • Proposed as answer by Fred Bao Tuesday, November 3, 2015 7:15 AM
    • Unproposed as answer by alanmarklewis Tuesday, November 3, 2015 9:02 AM
    • Marked as answer by alanmarklewis Tuesday, November 3, 2015 9:03 AM
    Monday, October 26, 2015 6:29 AM
  • Tried to reply a few days ago, this helped massively!

    Thanks for the help :)

    Tuesday, November 3, 2015 9:03 AM