Created
April 9, 2015 19:12
-
-
Save dvbobrov/6f13176f9eeffebae355 to your computer and use it in GitHub Desktop.
WPF backwards compatibility issue
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
namespace WpfApplication1 | |
{ | |
using System; | |
using System.ComponentModel; | |
using System.Diagnostics; | |
using System.Globalization; | |
using System.Runtime.CompilerServices; | |
using System.Windows; | |
using System.Windows.Data; | |
using WpfApplication1.Annotations; | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
DataContext = new ViewModel(); | |
} | |
} | |
public class ViewModel : INotifyPropertyChanged | |
{ | |
private string _value; | |
public string Value | |
{ | |
get | |
{ | |
return _value; | |
} | |
set | |
{ | |
if (value == _value) | |
{ | |
return; | |
} | |
_value = value; | |
OnPropertyChanged(); | |
} | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
public class Converter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
Debug.Print($"Convert value: {value}, parameter: {parameter}"); | |
return value; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
Debug.Print($"ConvertBack value: {value}, parameter: {parameter}"); | |
return 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
<Window x:Class="WpfApplication1.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:WpfApplication1" | |
mc:Ignorable="d" | |
d:DataContext="{d:DesignInstance local:ViewModel}" | |
Title="MainWindow" Height="350" Width="525"> | |
<Window.Resources> | |
<ResourceDictionary> | |
<local:Converter x:Key="Conv" /> | |
</ResourceDictionary> | |
</Window.Resources> | |
<StackPanel> | |
<TextBox Text="{Binding Value, Converter={StaticResource Conv}, | |
ConverterParameter='param', UpdateSourceTrigger=LostFocus}" /> | |
<TextBox /> | |
</StackPanel> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment