Archived
1
0

Ads development

This commit is contained in:
Michael Gordeev
2019-01-04 18:39:29 +03:00
parent 63249ebee4
commit 3a1f5d418f
10 changed files with 137 additions and 51 deletions
@@ -0,0 +1,53 @@
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Advertising.WinRT.UI;
using Windows.UI.Xaml.Media.Imaging;
using System.Diagnostics;
namespace FoxTube.Controls.Adverts
{
/// <summary>
/// Advert which is looks similar to video cards
/// </summary>
public sealed partial class CardAdvert : UserControl
{
NativeAdV2 advert;
public CardAdvert(NativeAdV2 ad)
{
InitializeComponent();
advert = ad;
Initialize();
}
public void Initialize()
{
title.Text = advert.Title;
image.Source = new BitmapImage(advert.MainImages.First().Url.ToUri());
if (advert.AdIcon == null)
contentGrid.ColumnDefinitions[0].Width = new GridLength(0);
else
icon.ProfilePicture = advert.AdIcon.Source;
if (string.IsNullOrWhiteSpace(advert.SponsoredBy))
sponsor.Visibility = Visibility.Collapsed;
else
sponsor.Text = advert.SponsoredBy;
if (!string.IsNullOrWhiteSpace(advert.Rating))
info.Text += $" {advert.Rating}";
if (string.IsNullOrWhiteSpace(advert.CallToActionText) && string.IsNullOrWhiteSpace(advert.Price))
desc.Visibility = Visibility.Collapsed;
else if (!string.IsNullOrWhiteSpace(advert.CallToActionText))
desc.Text = advert.CallToActionText;
else
desc.Text = advert.Price;
}
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
Height = e.NewSize.Width * 0.75;
}
}
}