我必须将textBlock idName的Text={Binding Id}
从一个帧传递到另一个帧。该文本是来自SQLite数据库的Id。我有一个定义项目的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>
我在代码背后使用:
this.Frame.Navigate(typeof(FilmInfo), idName.Text);
但是idName.Text
是一个ItemTemplate。
我该怎么做?
答案 0 :(得分:0)
我假设必须以某种方式在ListView中选择项目才能对其采取行动......如果是这样,您可以直接使用该项目。
YourClassName selectedFilm = YourListView.SelectedItem as YourClassName;
If(selectedFilm != null)
{
this.Frame.Navigate(typeof(FilmInfo), selectedFilm.Id);
}
评论后更新
好的......如果你正在使用项目点击事件,你可以做同样的事情......
private void ItemClickEvent(object sender, ItemClickEventArgs e)
{
YourClassName selectedFilm = e.ClickedItem as YourClassName;
if(selectedFilm != null)
{
this.Frame.Navigate(typeof(FilmInfo), selectedFilm.Id);
}
}