简体   繁体   English

如何在用户控件Universal Windows App中点击的图像上导航框架?

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

相关问题 如何在 windows 通用应用程序中的页面之间导航? - How to navigate between pages in windows universal app? 如何获取MapElement的点击类型(MapControl)(Windows 10通用应用程序) - How to get MapElement tapped type (MapControl) (Windows 10 universal app) Windows Universal App 8.1自定义用户控件 - Windows Universal App 8.1 Custom User Control 从 Windows 通用应用程序上的视图模型调用框架控件 - Call frame control from viewmodel on Windows universal app 是否可以知道用户在Windows运行时(通用)应用程序中的ListView或GridView项目中的位置? - Is it possible to know where the user tapped in a ListView or GridView item in Windows Runtime (Universal) App? 如何在Windows Phone 8.1通用商店应用中正确导航后退堆栈 - How to properly navigate backstack in Windows Phone 8.1 universal store app 如何在通用Windows应用程序中更新WebView页面控件值 - How to update webview page control value in universal windows app 如何从Windows Phone 8.1中的用户控件导航到另一个页面 - How to navigate to another Page from a User Control in Windows Phone 8.1 通用Windows应用中的图像处理 - Image manipulations in Universal Windows app 在通用Windows应用程序的框架中加载背景页面 - Background page loading in a frame in universal windows app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM