Created
February 16, 2018 09:50
-
-
Save michael-hawker/becf8c1b9f781a91eeebb747c2955233 to your computer and use it in GitHub Desktop.
UWP Custom Markup Extension Example
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.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; | |
} | |
} | |
} |
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
<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