Skip to content

Instantly share code, notes, and snippets.

@michael-hawker
Created February 16, 2018 09:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-hawker/becf8c1b9f781a91eeebb747c2955233 to your computer and use it in GitHub Desktop.
Save michael-hawker/becf8c1b9f781a91eeebb747c2955233 to your computer and use it in GitHub Desktop.
UWP Custom Markup Extension Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Markup;
namespace CustomMarkupExtensionRS3
{
[MarkupExtensionReturnType(ReturnType = typeof(int))]
public sealed class Calc : MarkupExtension
{
private string _text;
public string Eq
{
get { return _text; }
set { _text = value; }
}
public Calc()
{
}
protected override object ProvideValue()
{
int.TryParse(Eq, out int value);
return 5 + value;
}
}
}
<Page
x:Class="CustomMarkupExtensionRS3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CustomMarkupExtensionRS3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Rectangle Fill="Red" Width="100" Height="{local:Calc Eq=10}" />
</StackPanel>
</Page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment