locked
Data binding

    Question

  • Hi!

    I am newbie in Windows app development, so an easy question... How can i get item Uri in Play_Button_Click method, when AppBarButton is clicked?

    XAML

            <GridView
                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemGridView"
                AutomationProperties.Name="Grouped Items"
                Grid.RowSpan="2"
                Padding="116,137,40,46"
                ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                SelectionMode="None"
                IsSwipeEnabled="false"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick">
    
                
    
    
                <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" Orientation="Horizontal" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
                                <TextBlock Text="{Binding Title}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextBlockStyle}" Height="90" Width="150" Margin="15,0,0,0"/>
                                <AppBarButton Icon="Play" Height="100" Width="100" Click="Play_Button_Click"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
                <GridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <ItemsWrapGrid GroupPadding="0,0,70,0"/>
                    </ItemsPanelTemplate>
                </GridView.ItemsPanel>

    Method

    void iRadio::GroupedItemsPage::Play_Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { (void) sender; // Unused parameter auto uri = safe_cast<Data::SampleDataItem^>(e->OriginalSource)->Uri; }

    Of course now i get an exception.


    Wednesday, May 07, 2014 8:57 PM

Answers

  • Hi,

    I do not quite understand your question. What's meaning about Uri? where the Uri contain in. Do you mean the Uri contain in the groupedItemsViewSource item. If so, you can define a index value in the groupedItemsViewSource item and bind the AppBarButton's Tag property to the index. Then in the Button_Click event you can get the tag vaule and then use the value to check which item you click in the groupedItemsViewSource and then get the Uri Value. You can see the link below:

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/fe5cdac8-8625-4b66-bca7-f1dc63f0e4d8/button-in-a-gridview?forum=winappswithcsharp

    And for data binding i recommand you can refer to the links:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758320.aspx

    XAML data binding sample

    Best Wishes!


    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. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, May 08, 2014 2:54 AM