Skip to content

Instantly share code, notes, and snippets.

@wtuts
Created June 21, 2014 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtuts/ff5f793d9926469f58b1 to your computer and use it in GitHub Desktop.
Save wtuts/ff5f793d9926469f58b1 to your computer and use it in GitHub Desktop.
in app purchase
public ObservableCollection<ProductItem> picItems = new ObservableCollection<ProductItem>();
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
RenderStoreItems();
base.OnNavigatedTo(e);
}
private async void RenderStoreItems()
{
picItems.Clear();
try
{
//StoreManager mySM = new StoreManager();
ListingInformation li = await Store.CurrentApp.LoadListingInformationAsync();
foreach (string key in li.ProductListings.Keys)
{
ProductListing pListing = li.ProductListings[key];
System.Diagnostics.Debug.WriteLine(key);
string status = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? "Purchased" : pListing.FormattedPrice;
string imageLink = string.Empty;
picItems.Add(
new ProductItem {
imgLink = key.Equals("AdBlocker") ? "block-ads.png" : "block-ads.png",
Name = pListing.Name,
Status = status,
key = key,
BuyNowButtonVisible = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible
}
);
}
pics.ItemsSource = picItems;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
<ScrollViewer HorizontalAlignment="Left" Margin="12,0,12,0" Grid.Row="1">
<ItemsControl x:Name="pics">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Margin="4" Source="{Binding imgLink}"/>
<StackPanel Grid.Column="1" Margin="0,30,0,0">
<TextBlock Foreground="white" FontWeight="ExtraBold" Text="{Binding Name}" />
<TextBlock Foreground="white" FontWeight="Normal" Text="{Binding Status}" />
<Button Content="Buy Now" Visibility="{Binding BuyNowButtonVisible}" Click="ButtonBuyNow_Clicked" Tag="{Binding key}" />
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
public class ProductItem
{
public string imgLink { get; set; }
public string Status { get; set; }
public string Name { get; set; }
public string key { get; set; }
public System.Windows.Visibility BuyNowButtonVisible { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment