Button to remove ads (in app purchase) does not disappear

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 06:15:46

问题


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;
    }

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/43052338/button-to-remove-ads-in-app-purchase-does-not-disappear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!