简体   繁体   English

将Listview.ItemTemplate的文本传递到另一个框架uwp

[英]Pass text of Listview.ItemTemplate to antoher frame uwp

I have to pass the Text={Binding Id} of textBlock idName from a frame to another frame. 我必须将textBlock idName的Text={Binding Id}从一个框架传递到另一个框架。 the text is an Id from an SQLite database. 文本是来自SQLite数据库的ID。 I have an Listview.ItemTemplate that define the item 我有一个Listview.ItemTemplate定义项目

<ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid Height="Auto" Margin="0,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="12,0,0,0">

                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock x:Name="idName" Text="{Binding Id}" FontSize="12" VerticalAlignment="Center" Grid.Column="0" Margin="5,0,12,0"/>
                                    <RelativePanel Grid.Column="1">
                                        <TextBlock x:Name="titleBlock" Text="{Binding Title}" FontSize="25" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                        <TextBlock x:Name="directorLabel" Text="REGISTA:" FontSize="20" RelativePanel.Below="titleBlock" FontWeight="Light"/>
                                        <TextBlock x:Name="directorBlock" Text="{Binding Director}"  FontSize="20" RelativePanel.Below="titleBlock" RelativePanel.RightOf="directorLabel"/>
                                        <TextBlock x:Name="yearLabel" Text="ANNO:" FontSize="20" FontWeight="Light" RelativePanel.RightOf="directorBlock" Margin="12,0,0,0" RelativePanel.Below="titleBlock"/>
                                        <TextBlock x:Name="yearBlock" Text="{Binding Year}" FontSize="20" RelativePanel.Below="titleBlock" RelativePanel.RightOf="yearLabel"/>
                                    </RelativePanel>
                                </Grid>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>

I use in the Code Behind this: 我在此背后的代码中使用:

this.Frame.Navigate(typeof(FilmInfo), idName.Text);

but idName.Text is an ItemTemplate. 但是idName.Text是一个ItemTemplate。

How can I do that? 我怎样才能做到这一点?

I'm assuming the item must somehow be selected in the ListView in order to take action on it... if so, you can use the item directly. 我假设必须以某种方式在ListView中选择该项目才能对其执行操作...如果是这样,则可以直接使用该项目。

YourClassName selectedFilm = YourListView.SelectedItem as YourClassName;
If(selectedFilm != null)
{
    this.Frame.Navigate(typeof(FilmInfo), selectedFilm.Id);
}

UPDATE after comment 评论后更新

OK... if you're using the item click event, you can do the same thing... 确定...如果您正在使用项目单击事件,则可以执行相同的操作...

private void ItemClickEvent(object sender, ItemClickEventArgs e)
{
    YourClassName selectedFilm = e.ClickedItem as YourClassName;
    if(selectedFilm != null)
    {
        this.Frame.Navigate(typeof(FilmInfo), selectedFilm.Id);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将属性名称动态传递给 ListView.ItemTemplate 以进行绑定 (UWP) - Unable to pass property name dynamically to ListView.ItemTemplate to bind (UWP) ListView.ItemTemplate的MultiBinding DataTemplate? - MultiBinding DataTemplate for ListView.ItemTemplate? 按特定值中的值对 ListView 或 ListView.ItemTemplate 进行排序 - Sort a ListView or a ListView.ItemTemplate by a value in a specific UWP#没有显示ListView.ItemTemplate,因为我从List更改为ObservableCollection和async - UWP # not showing ListView.ItemTemplate since I changed from List to ObservableCollection and async 如何将事件添加到 ListView.ItemTemplate - How to add event to ListView.ItemTemplate ItemTemplateSelector 和 ListView.ItemTemplate 的区别 - Difference between ItemTemplateSelector and ListView.ItemTemplate FindAncestor在ListView.ItemTemplate中不适用于UserControl - FindAncestor does not work for UserControl in ListView.ItemTemplate 未设置ListView.ItemTemplate并且未触发事件 - ListView.ItemTemplate not being set and events not firing GroupDisplayBinding 属性导致 ListView.ItemTemplate 消失 - GroupDisplayBinding attribute causes the ListView.ItemTemplate to disappear Xamarin按钮命令(在ListView.ItemTemplate内部)未触发 - Xamarin Button Command (inside of ListView.ItemTemplate) Not Firing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM