[英]How to navigate frame on image tapped in a user control Universal Windows App?
i have an image on Tapping it i was navigating to another page 我在点击它时有图像,我正在导航到另一页
<Image Source="{Binding ImagePath}" Tapped="Image_Tapped_1"/>
C#
C#
private void Image_Tapped_1(object sender, TappedRoutedEventArgs e)
{
var gameData = (sender as Image).DataContext as DataClass;
this.Frame.Navigate(typeof(GamePage), gameData);
}
Now I have created a User Control for adaptive UI and my code look like this now 现在,我已经为自适应UI创建了一个用户控件,我的代码现在看起来像这样
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="VisualStateMin600">
<VisualState.Setters>
<Setter Target="image.(FrameworkElement.Width)" Value="NaN"/>
</VisualState.Setters>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600"/>
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="VisualStateMin0">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1"/>
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image x:Name="image" Source="{Binding ImagePath}" Tapped="image_Tapped_1" Width="250" />
</Grid>
The problem now is that how will i navigate to the other page the tapped property is not working with in the UserControl ? 现在的问题是,我将如何导航到UserControl中无法使用tapped属性的其他页面?
尝试((Frame)Window.Current.Content).NavigateTo
或根据需要在App.Xaml.cs上将公共属性设置为根框架,以便您始终可以访问它。
In the code-behind of your user control (let's call it ImageControl), you will have to manage an event handler like this: 在用户控件的代码背后(我们将其称为ImageControl),您将必须管理如下事件处理程序:
public sealed partial class ImageControl : UserControl
{
public event EventHandler ImageTapped;
public void image_Tapped_1(object sender, TappedRoutedEventArgs e)
{
if (ImageTapped != null)
{
ImageTapped(this, EventArgs.Empty);
}
}
}
And from XAML where you declare your ImageControl : 在XAML中,您声明ImageControl:
<local:ImageControl ImageTapped="ImageControl_ImageTapped" />
And finally from C# code behind : 最后是后面的C#代码:
private void ImageControl_ImageTapped(object sender, EventArgs e)
{
this.Frame.Navigate(typeof(YourOtherPage));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.