Skip to content

Instantly share code, notes, and snippets.

@sakapon
Last active July 3, 2016 14:44
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 sakapon/9bb1faba9de1a320cc2ecc863f2aa4d5 to your computer and use it in GitHub Desktop.
Save sakapon/9bb1faba9de1a320cc2ecc863f2aa4d5 to your computer and use it in GitHub Desktop.
BindingSample / ExpandoBindingWpf
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ExpandoBindingWpf"
xmlns:Dynamic="clr-namespace:System.Dynamic;assembly=System.Core"
x:Class="ExpandoBindingWpf.MainWindow"
Title="Expando Binding" Height="400" Width="600" FontSize="36">
<Window.DataContext>
<Dynamic:ExpandoObject/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Text="{Binding Input, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Output}" TextWrapping="Wrap" Grid.Row="1"/>
</Grid>
</Window>
using System;
using System.ComponentModel;
using System.Windows;
namespace ExpandoBindingWpf
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
dynamic model = DataContext;
((INotifyPropertyChanged)model).PropertyChanged += (o, e) =>
{
if (e.PropertyName == "Input")
model.Output = model.Input?.ToUpper();
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment