[英]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.