Created
August 2, 2018 18:18
-
-
Save adhamali450/ffe830562f80cf232ae551ada073f404 to your computer and use it in GitHub Desktop.
The renderer that is specifically will implement AcrylicMaterialBrush for the AcrylicTappedPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Threading.Tasks; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Markup; | |
using Windows.UI.Xaml.Media; | |
using Windows.UI.Xaml.Media.Imaging; | |
using Xamarin.Forms.Platform.UWP; | |
using XTournament.UWP.CustomRenderers; | |
using XTournament.CustomControls; | |
using XTournament.UWP.Utils; | |
using Windows.UI; | |
[assembly: ExportRenderer(typeof(AcrylicTabbedPage), typeof(AcrylicTabbedPageRenderer))] | |
namespace XTournament.UWP.CustomRenderers | |
{ | |
public class AcrylicTabbedPageRenderer : TabbedPageRenderer | |
{ | |
protected async override void OnElementChanged(VisualElementChangedEventArgs e) | |
{ | |
base.OnElementChanged(e); | |
var pivotSource = Element as AcrylicTabbedPage; | |
var pivotResult = Control as FormsPivot; | |
if (pivotResult != null) | |
{ | |
if (pivotSource.AcrylicSupportForUwp) | |
{ | |
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.XamlCompositionBrushBase")) | |
{ | |
AcrylicBrush myBrush = new AcrylicBrush(); | |
myBrush.BackgroundSource = (AcrylicBackgroundSource)Enum.Parse(typeof(AcrylicBackgroundSource), pivotSource.BackgroundSource.ToString()); | |
myBrush.TintColor = pivotSource.TintColor.ToUwpColor(); | |
myBrush.FallbackColor = pivotSource.FallbackColor.ToUwpColor(); | |
myBrush.TintOpacity = pivotSource.TintOpacity; | |
pivotResult.ToolbarBackground = myBrush; | |
} | |
else | |
{ | |
SolidColorBrush myBrush = new SolidColorBrush(pivotSource.TintColor.ToUwpColor()); | |
pivotResult.Background = myBrush; | |
} | |
} | |
//taps | |
await RenderHeaderTaps(pivotResult) | |
} | |
} | |
private static async Task RenderHeaderTaps(FormsPivot pivotResult) | |
{ | |
StringReader headerTemplateXaml = new StringReader( | |
@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""> | |
<TextBlock FontSize=""22"" Text=""{Binding Title}"" Margin=""5,35,0,5""/> | |
</DataTemplate>"); // 5 and 35 are harcoded values to make ti appearince bettwe | |
var headerTemplate = XamlReader.Load(await headerTemplateXaml.ReadToEndAsync()); | |
pivotResult.HeaderTemplate = headerTemplate as DataTemplate; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment