移除广告的按钮(在应用内购买)不会消失 [英] Button to remove ads (in app purchase) does not disappear

查看:24
本文介绍了移除广告的按钮(在应用内购买)不会消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 uwp 应用程序,并且我有应用程序内广告(仅在主页上),可以通过单击按钮(在应用程序购买中)来删除这些广告.我正在使用 CurrentAppSimulator(我仍在测试)并且我已经成功移除了广告,但是我遇到了问题.例如:我通过单击按钮删除广告,然后按钮和广告消失,但如果我导航到应用程序的另一个页面(例如设置)并返回主页面,则不再显示广告,但它在那里 删除广告的按钮.这是我的代码(当点击按钮时,它删除了宣传和按钮):

I'm developing a uwp app, and I have in-app advertising (only on the main page) that can be removed by clicking in a button (in app purchase). I am using CurrentAppSimulator (I am still testing) and I already have the removal of the advertising to be done successfully, but I have a problem. For example: I remove the advertising by clicking the button, then the button and the advertising disappear but if I navigate to another page of the app (for example to the settings) and return to the main page, the advertising is no longer displayed but it is there The button to remove the advertising. This is my code (it removes the publicity and the button, when the button is clicked):

if (results.Status == ProductPurchaseStatus.Succeeded)
    {
      RemoveAds.Visibility = Visibility.Collapsed;
      Ad.Visibility = Visibility.Collapsed;
    }

在我的 XAML 中,我的两个元素(按钮和广告)都显示为:Visibility="Visible"

In my XAML I have both elements (button and advertising) appear as: Visibility="Visible"

推荐答案

当您重新加载主页时(即使在导航回时),该按钮将从您的 XAML 获取可见性设置,因为上面的代码仅在按钮处于点击.您需要通过重载 OnNavigatedTo 方法在页面加载时运行类似的代码.在该方法中,您可以检查是否已进行购买并将 RemoveAds.Visibility 设置为 Collapsed.

When you reload the Main page (even when navigating back), that button is getting the Visibility setting from your XAML because that code above only runs when the button is clicked. You need to run similar code as the page loads, by overloading OnNavigatedTo method. In that method, you can check that the purchase has been made and set the RemoveAds.Visibility to Collapsed.

如果您想在视图模型中执行此操作,您可以拥有一个返回购买状态的属性,并将 RemoveAds.Visibility 属性绑定到它.

If you want to do this in your view model, you can have a property that returns the state of the purchase, and bind the RemoveAds.Visibility property to it.

这篇关于移除广告的按钮(在应用内购买)不会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆