Created
February 19, 2012 18:13
-
-
Save mwisnicki/1864931 to your computer and use it in GitHub Desktop.
Generic solution for DataTemplate-based editor of value-like types (structs, enums, strings) ?
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
*.suo | |
*.*proj.user | |
_ReSharper.*/ | |
Debug/ | |
Release/ |
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
<Application x:Class="WpfValueTypeEditor.App" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
StartupUri="MainWindow.xaml"> | |
<Application.Resources> | |
</Application.Resources> | |
</Application> |
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.Configuration; | |
using System.Data; | |
using System.Linq; | |
using System.Windows; | |
namespace WpfValueTypeEditor { | |
/// <summary> | |
/// Interaction logic for App.xaml | |
/// </summary> | |
public partial class App : Application { | |
} | |
} |
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.Reflection; | |
using System.Resources; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Windows; | |
// General Information about an assembly is controlled through the following | |
// set of attributes. Change these attribute values to modify the information | |
// associated with an assembly. | |
[assembly: AssemblyTitle("WpfValueTypeEditor")] | |
[assembly: AssemblyDescription("")] | |
[assembly: AssemblyConfiguration("")] | |
[assembly: AssemblyCompany("")] | |
[assembly: AssemblyProduct("WpfValueTypeEditor")] | |
[assembly: AssemblyCopyright("Copyright © 2012")] | |
[assembly: AssemblyTrademark("")] | |
[assembly: AssemblyCulture("")] | |
// Setting ComVisible to false makes the types in this assembly not visible | |
// to COM components. If you need to access a type in this assembly from | |
// COM, set the ComVisible attribute to true on that type. | |
[assembly: ComVisible(false)] | |
//In order to begin building localizable applications, set | |
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file | |
//inside a <PropertyGroup>. For example, if you are using US english | |
//in your source files, set the <UICulture> to en-US. Then uncomment | |
//the NeutralResourceLanguage attribute below. Update the "en-US" in | |
//the line below to match the UICulture setting in the project file. | |
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | |
[assembly: ThemeInfo( | |
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | |
//(used if a resource is not found in the page, | |
// or application resource dictionaries) | |
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | |
//(used if a resource is not found in the page, | |
// app, or any theme specific resource dictionaries) | |
)] | |
// Version information for an assembly consists of the following four values: | |
// | |
// Major Version | |
// Minor Version | |
// Build Number | |
// Revision | |
// | |
// You can specify all the values or you can default the Build and Revision Numbers | |
// by using the '*' as shown below: | |
// [assembly: AssemblyVersion("1.0.*")] | |
[assembly: AssemblyVersion("1.0.0.0")] | |
[assembly: AssemblyFileVersion("1.0.0.0")] |
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.ObjectModel; | |
using System.ComponentModel; | |
using System.Globalization; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Markup; | |
namespace Hardcodet.Wpf.DataBinding | |
{ | |
/// <summary> | |
/// A base class for custom markup extension which provides properties | |
/// that can be found on regular <see cref="Binding"/> markup extension.<br/> | |
/// See: http://www.hardcodet.net/2008/04/wpf-custom-binding-class | |
/// </summary> | |
[MarkupExtensionReturnType(typeof(object))] | |
public abstract class BindingDecoratorBase : MarkupExtension | |
{ | |
/// <summary> | |
/// The decorated binding class. | |
/// </summary> | |
private Binding binding = new Binding(); | |
//check documentation of the Binding class for property information | |
#region properties | |
/// <summary> | |
/// The decorated binding class. | |
/// </summary> | |
[Browsable(false)] | |
public Binding Binding | |
{ | |
get { return binding; } | |
set { binding = value; } | |
} | |
[DefaultValue(null)] | |
public object AsyncState | |
{ | |
get { return binding.AsyncState; } | |
set { binding.AsyncState = value; } | |
} | |
[DefaultValue(false)] | |
public bool BindsDirectlyToSource | |
{ | |
get { return binding.BindsDirectlyToSource; } | |
set { binding.BindsDirectlyToSource = value; } | |
} | |
[DefaultValue(null)] | |
public IValueConverter Converter | |
{ | |
get { return binding.Converter; } | |
set { binding.Converter = value; } | |
} | |
[DefaultValue(null)] | |
public object TargetNullValue | |
{ | |
get { return binding.TargetNullValue; } | |
set { binding.TargetNullValue = value; } | |
} | |
[TypeConverter(typeof(CultureInfoIetfLanguageTagConverter)), DefaultValue(null)] | |
public CultureInfo ConverterCulture | |
{ | |
get { return binding.ConverterCulture; } | |
set { binding.ConverterCulture = value; } | |
} | |
[DefaultValue(null)] | |
public object ConverterParameter | |
{ | |
get { return binding.ConverterParameter; } | |
set { binding.ConverterParameter = value; } | |
} | |
[DefaultValue(null)] | |
public string ElementName | |
{ | |
get { return binding.ElementName; } | |
set { binding.ElementName = value; } | |
} | |
[DefaultValue(null)] | |
public object FallbackValue | |
{ | |
get { return binding.FallbackValue; } | |
set { binding.FallbackValue = value; } | |
} | |
[DefaultValue(false)] | |
public bool IsAsync | |
{ | |
get { return binding.IsAsync; } | |
set { binding.IsAsync = value; } | |
} | |
[DefaultValue(BindingMode.Default)] | |
public BindingMode Mode | |
{ | |
get { return binding.Mode; } | |
set { binding.Mode = value; } | |
} | |
[DefaultValue(false)] | |
public bool NotifyOnSourceUpdated | |
{ | |
get { return binding.NotifyOnSourceUpdated; } | |
set { binding.NotifyOnSourceUpdated = value; } | |
} | |
[DefaultValue(false)] | |
public bool NotifyOnTargetUpdated | |
{ | |
get { return binding.NotifyOnTargetUpdated; } | |
set { binding.NotifyOnTargetUpdated = value; } | |
} | |
[DefaultValue(false)] | |
public bool NotifyOnValidationError | |
{ | |
get { return binding.NotifyOnValidationError; } | |
set { binding.NotifyOnValidationError = value; } | |
} | |
[DefaultValue(null)] | |
public PropertyPath Path | |
{ | |
get { return binding.Path; } | |
set { binding.Path = value; } | |
} | |
[DefaultValue(null)] | |
public RelativeSource RelativeSource | |
{ | |
get { return binding.RelativeSource; } | |
set { binding.RelativeSource = value; } | |
} | |
[DefaultValue(null)] | |
public object Source | |
{ | |
get { return binding.Source; } | |
set { binding.Source = value; } | |
} | |
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] | |
public UpdateSourceExceptionFilterCallback UpdateSourceExceptionFilter | |
{ | |
get { return binding.UpdateSourceExceptionFilter; } | |
set { binding.UpdateSourceExceptionFilter = value; } | |
} | |
[DefaultValue(UpdateSourceTrigger.Default)] | |
public UpdateSourceTrigger UpdateSourceTrigger | |
{ | |
get { return binding.UpdateSourceTrigger; } | |
set { binding.UpdateSourceTrigger = value; } | |
} | |
[DefaultValue(false)] | |
public bool ValidatesOnDataErrors | |
{ | |
get { return binding.ValidatesOnDataErrors; } | |
set { binding.ValidatesOnDataErrors = value; } | |
} | |
[DefaultValue(false)] | |
public bool ValidatesOnExceptions | |
{ | |
get { return binding.ValidatesOnExceptions; } | |
set { binding.ValidatesOnExceptions = value; } | |
} | |
[DefaultValue(null)] | |
public string XPath | |
{ | |
get { return binding.XPath; } | |
set { binding.XPath = value; } | |
} | |
[DefaultValue(null)] | |
public Collection<ValidationRule> ValidationRules | |
{ | |
get { return binding.ValidationRules; } | |
} | |
[DefaultValue(null)] | |
public string StringFormat | |
{ | |
get { return binding.StringFormat; } | |
set { binding.StringFormat = value; } | |
} | |
[DefaultValue("")] | |
public string BindingGroupName | |
{ | |
get { return binding.BindingGroupName; } | |
set { binding.BindingGroupName = value; } | |
} | |
#endregion | |
/// <summary> | |
/// This basic implementation just sets a binding on the targeted | |
/// <see cref="DependencyObject"/> and returns the appropriate | |
/// <see cref="BindingExpressionBase"/> instance.<br/> | |
/// All this work is delegated to the decorated <see cref="Binding"/> | |
/// instance. | |
/// </summary> | |
/// <returns> | |
/// The object value to set on the property where the extension is applied. | |
/// In case of a valid binding expression, this is a <see cref="BindingExpressionBase"/> | |
/// instance. | |
/// </returns> | |
/// <param name="provider">Object that can provide services for the markup | |
/// extension.</param> | |
public override object ProvideValue(IServiceProvider provider) | |
{ | |
//create a binding and associate it with the target | |
return binding.ProvideValue(provider); | |
} | |
/// <summary> | |
/// Validates a service provider that was submitted to the <see cref="ProvideValue"/> | |
/// method. This method checks whether the provider is null (happens at design time), | |
/// whether it provides an <see cref="IProvideValueTarget"/> service, and whether | |
/// the service's <see cref="IProvideValueTarget.TargetObject"/> and | |
/// <see cref="IProvideValueTarget.TargetProperty"/> properties are valid | |
/// <see cref="DependencyObject"/> and <see cref="DependencyProperty"/> | |
/// instances. | |
/// </summary> | |
/// <param name="provider">The provider to be validated.</param> | |
/// <param name="target">The binding target of the binding.</param> | |
/// <param name="dp">The target property of the binding.</param> | |
/// <returns>True if the provider supports all that's needed.</returns> | |
protected virtual bool TryGetTargetItems(IServiceProvider provider, out DependencyObject target, out DependencyProperty dp) | |
{ | |
target = null; | |
dp = null; | |
if (provider == null) return false; | |
//create a binding and assign it to the target | |
IProvideValueTarget service = (IProvideValueTarget)provider.GetService(typeof(IProvideValueTarget)); | |
if (service == null) return false; | |
//we need dependency objects / properties | |
target = service.TargetObject as DependencyObject; | |
dp = service.TargetProperty as DependencyProperty; | |
return target != null && dp != null; | |
} | |
} | |
} |
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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Markup; | |
using System.Windows.Media; | |
using System.Windows.Markup.Primitives; | |
using System.ComponentModel; | |
using System.Diagnostics; | |
namespace WpfValueTypeEditor | |
{ | |
/// <summary> | |
/// Binds directly to content of DataTemplate such that value-like binding targets will work. | |
/// </summary> | |
public class ContentBindingExtension : Hardcodet.Wpf.DataBinding.BindingDecoratorBase | |
{ | |
public ContentBindingExtension() | |
{ | |
// default constructor needed to silence ReSharper(?) | |
if (this != null) { } // keep for debugging | |
} | |
// TODO handle struct updates | |
private bool _sealed = false; | |
public override object ProvideValue(IServiceProvider serviceProvider) | |
{ | |
var target = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; | |
if (Path == null) | |
Path = new PropertyPath("."); | |
// reevaluate if this is an intermediate value | |
if (IsTargetIntermediate(target)) | |
return this; | |
// find our ContentPresenter and ContentControl | |
var control = (FrameworkElement)target.TargetObject; | |
var contentPresenter = (ContentPresenter)control.TemplatedParent; | |
// presenterParent is always a ContentControl (XXX is this true?) | |
var presenterParent = contentPresenter.TemplatedParent; | |
var contentSourceProperty = GetDependencyProperty(presenterParent, contentPresenter.ContentSource); | |
var parentBinding = default(BindingExpression); | |
/* | |
Plan for ItemsControl: | |
ItemsControl | |
1. Control (TextBox) has TemplatedParent=(ContentPresenter) and DataContext=(value) | |
2. (ContentPresenter) has TemplatedParent=ListBoxItem(ContentControl) and same DC | |
3. ListBoxItem can be disconnected, but has VisualParent=VirtualizingStackPanel(Control) and same DC | |
4. that visual parent has TemplatedParent=ItemsPresenter and DC=RootModel{of ItemsControl binding source?) | |
5. which has TemplatedParent=ListBox(ItemsControl) with ItemsSource and same DC | |
6. ItemsControl.ItemsSource has actual collection | |
ContentControl | |
1. TextBox(Control) has TemplatedParent=(ContentPresenter) and DC=(value) | |
2. (ContentPresenter) has TemplatedParent=(ContentControl), ContentSource and same DC | |
3. (ContentControl) has {ContentSource} with valid expression | |
Difference: {3}.{Parent}.TemplatedParent is ItemsPresenter when inside ItemsControl | |
*/ | |
if (presenterParent is ListBoxItem) | |
{ | |
// TODO create a binding to intermediate object that captures bound collection and index | |
var itemParent = (FrameworkElement)VisualTreeHelper.GetParent(presenterParent); | |
var itemsPresenter = (ItemsPresenter) itemParent.TemplatedParent; | |
var itemsControl = (ItemsControl) itemsPresenter.TemplatedParent; | |
var collectionBinding = itemsControl.GetBindingExpression(ItemsControl.ItemsSourceProperty); | |
var list = itemsControl.ItemsSource as IList; | |
var index = itemsControl.ItemContainerGenerator.IndexFromContainer(presenterParent); | |
var itemRef = new ListItemRef(list, index); | |
return new Binding | |
{ | |
Source = itemRef, | |
Path = new PropertyPath("Value") | |
}.ProvideValue(serviceProvider); | |
return base.ProvideValue(serviceProvider); | |
} | |
// once initialized we can't change anything | |
if (_sealed) | |
return base.ProvideValue(serviceProvider); | |
if (presenterParent is FrameworkElement) | |
{ | |
parentBinding = (presenterParent as FrameworkElement).GetBindingExpression(contentSourceProperty); | |
} | |
else | |
{ | |
// what else could it be ? | |
Debug.Fail("Unknown type of parent control"); | |
return base.ProvideValue(serviceProvider); | |
} | |
// TODO respect this.Path and other properties | |
if (parentBinding == null) | |
return base.ProvideValue(serviceProvider); | |
var parentPath = parentBinding.ParentBinding.Path; | |
var path = parentPath; | |
var pathSeparator = Path.Path.StartsWith("[") ? "" : "."; | |
if (Path.Path != ".") | |
{ | |
// TODO merge PathParameters of current and parentPath and rewrite path expression | |
var newPath = parentPath.Path + pathSeparator + Path.Path; | |
var pathParameters = parentPath.PathParameters.ToArray(); | |
path = new PropertyPath(newPath, pathParameters); | |
} | |
#if false | |
Source = parentBinding.DataItem; | |
Path = path; | |
_sealed = true; | |
return base.ProvideValue(serviceProvider); | |
#else | |
var binding = new Binding | |
{ | |
Source = parentBinding.DataItem, | |
Path = path | |
}; | |
var bindingExpression = binding.ProvideValue(serviceProvider); | |
return bindingExpression; | |
#endif | |
} | |
private static DependencyProperty GetDependencyProperty(DependencyObject dpObject, string name) | |
{ | |
var type = dpObject.GetType(); | |
var properties = TypeDescriptor.GetProperties(dpObject); | |
foreach (PropertyDescriptor pd in properties) | |
{ | |
var dpd = DependencyPropertyDescriptor.FromProperty(pd); | |
if (dpd != null && dpd.Name == name) | |
return dpd.DependencyProperty; | |
} | |
return null; | |
} | |
/// <summary> | |
/// Checks if we have received intermediate object (eg. SharedDp) instead of final target. | |
/// </summary> | |
/// <remarks> | |
/// Returning MarkupExtension instance will re-evaluate value once final target is known. | |
/// </remarks> | |
/// <param name="target"></param> | |
/// <returns></returns> | |
private static bool IsTargetIntermediate(IProvideValueTarget target) | |
{ | |
// target can be a plain object ! | |
return (target.TargetObject != null && target.TargetObject.GetType().FullName == "System.Windows.SharedDp"); | |
//return !(target.TargetObject is DependencyObject); | |
} | |
} | |
} |
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="WpfValueTypeEditor.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:sys="clr-namespace:System;assembly=mscorlib" | |
xmlns:my="clr-namespace:WpfValueTypeEditor" | |
Title="MainWindow" | |
mc:Ignorable="d" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
d:DesignHeight="418" | |
d:DesignWidth="525" | |
SizeToContent="WidthAndHeight" | |
WindowStartupLocation="CenterScreen"> | |
<Window.Resources> | |
<my:RootModel x:Key="rootModel" String="A string"> | |
<my:RootModel.Point> | |
<my:Point X="1" | |
Y="2" /> | |
</my:RootModel.Point> | |
<my:RootModel.Points> | |
<my:Point X="1" | |
Y="2" /> | |
<my:Point X="3" | |
Y="4" /> | |
</my:RootModel.Points> | |
<my:RootModel.Strings> | |
<sys:String>abc</sys:String> | |
<sys:String>def</sys:String> | |
</my:RootModel.Strings> | |
</my:RootModel> | |
<DataTemplate DataType="{x:Type sys:String}" | |
x:Key="stringEditor"> | |
<DockPanel> | |
<TextBox | |
Text="{my:ContentBinding}" | |
Background="Red" | |
MouseDoubleClick="TextBox_MouseDoubleClick" /> | |
</DockPanel> | |
</DataTemplate> | |
<DataTemplate DataType="{x:Type my:Direction}" x:Key="directionEditor"> | |
<!-- watch out for recursion! --> | |
<ComboBox ItemsSource="{Binding Source={StaticResource rootModel}, Path=Directions}" | |
SelectedItem="{my:ContentBinding}" /> | |
</DataTemplate> | |
<DataTemplate DataType="{x:Type my:RootModel}"> | |
<StackPanel> | |
<StackPanel.Resources> | |
<DataTemplate DataType="{x:Type my:Point}"> | |
<StackPanel Orientation="Horizontal"> | |
<TextBlock Text="X=" /> | |
<TextBox Text="{my:ContentBinding Path=X}" /> | |
<TextBlock Text="Y=" /> | |
<TextBox Text="{Binding Y}" /> | |
</StackPanel> | |
</DataTemplate> | |
</StackPanel.Resources> | |
<TextBlock Text="Direction (direct):" /> | |
<ComboBox ItemsSource="{Binding Source={StaticResource rootModel}, Path=Directions}" | |
SelectedItem="{Binding Direction}" /> | |
<TextBlock Text="Direction (templated):" /> | |
<ContentControl Content="{Binding Direction}" | |
ContentTemplate="{StaticResource directionEditor}" /> | |
<TextBlock Text="Point (direct):" /> | |
<StackPanel Orientation="Horizontal"> | |
<TextBlock Text="X=" /> | |
<TextBox Text="{Binding Path=Point.X}" /> | |
<TextBlock Text="Y=" /> | |
<TextBox Text="{Binding Path=Point.Y}" | |
MouseDoubleClick="TextBox_MouseDoubleClick" /> | |
</StackPanel> | |
<TextBlock Text="Point (templated):" /> | |
<ContentControl Content="{Binding Point}" /> | |
<TextBlock Text="Points:" /> | |
<ListBox ItemsSource="{Binding Points}" /> | |
<TextBlock Text="String (direct):" /> | |
<TextBox Text="{Binding Path=String}" | |
MouseDoubleClick="TextBox_MouseDoubleClick" /> | |
<TextBlock Text="String (with template):" /> | |
<ContentControl Content="{Binding Path=String}" | |
ContentTemplate="{StaticResource stringEditor}" /> | |
<TextBlock Text="Strings:" /> | |
<ListBox ItemsSource="{Binding Strings}" | |
ItemTemplate="{StaticResource stringEditor}" /> | |
</StackPanel> | |
</DataTemplate> | |
</Window.Resources> | |
<Grid> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="1*" /> | |
<ColumnDefinition Width="1*" /> | |
</Grid.ColumnDefinitions> | |
<ContentControl Content="{StaticResource rootModel}" /> | |
<ContentControl Content="{StaticResource rootModel}" | |
Grid.Column="1" /> | |
</Grid> | |
</Window> |
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.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace WpfValueTypeEditor { | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window { | |
public MainWindow() { | |
InitializeComponent(); | |
} | |
private void ContentControl_MouseDoubleClick(object sender, MouseButtonEventArgs e) | |
{ | |
var control = sender as ContentControl; | |
var binding = control.GetBindingExpression(ContentControl.ContentProperty); | |
var unused = binding != null; | |
} | |
private void TextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) | |
{ | |
// aaa | |
var control = sender as TextBox; | |
var binding = control.GetBindingExpression(TextBox.TextProperty); | |
var unused = binding != null; | |
var parentBinding = ((control.TemplatedParent as ContentPresenter).TemplatedParent as ContentControl). | |
GetBindingExpression(ContentControl.ContentProperty); | |
control.SetBinding(TextBox.TextProperty, | |
new Binding { Source = parentBinding.DataItem, Path = parentBinding.ParentBinding.Path }); | |
} | |
} | |
} |
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
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// Runtime Version:4.0.30319.239 | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace WpfValueTypeEditor.Properties { | |
/// <summary> | |
/// A strongly-typed resource class, for looking up localized strings, etc. | |
/// </summary> | |
// This class was auto-generated by the StronglyTypedResourceBuilder | |
// class via a tool like ResGen or Visual Studio. | |
// To add or remove a member, edit your .ResX file then rerun ResGen | |
// with the /str option, or rebuild your VS project. | |
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] | |
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] | |
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] | |
internal class Resources { | |
private static global::System.Resources.ResourceManager resourceMan; | |
private static global::System.Globalization.CultureInfo resourceCulture; | |
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] | |
internal Resources() { | |
} | |
/// <summary> | |
/// Returns the cached ResourceManager instance used by this class. | |
/// </summary> | |
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] | |
internal static global::System.Resources.ResourceManager ResourceManager { | |
get { | |
if ((resourceMan == null)) { | |
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfValueTypeEditor.Properties.Resources", typeof(Resources).Assembly); | |
resourceMan = temp; | |
} | |
return resourceMan; | |
} | |
} | |
/// <summary> | |
/// Overrides the current thread's CurrentUICulture property for all | |
/// resource lookups using this strongly typed resource class. | |
/// </summary> | |
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] | |
internal static global::System.Globalization.CultureInfo Culture { | |
get { | |
return resourceCulture; | |
} | |
set { | |
resourceCulture = 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
<?xml version="1.0" encoding="utf-8"?> | |
<root> | |
<!-- | |
Microsoft ResX Schema | |
Version 2.0 | |
The primary goals of this format is to allow a simple XML format | |
that is mostly human readable. The generation and parsing of the | |
various data types are done through the TypeConverter classes | |
associated with the data types. | |
Example: | |
... ado.net/XML headers & schema ... | |
<resheader name="resmimetype">text/microsoft-resx</resheader> | |
<resheader name="version">2.0</resheader> | |
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> | |
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> | |
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> | |
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> | |
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> | |
<value>[base64 mime encoded serialized .NET Framework object]</value> | |
</data> | |
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> | |
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> | |
<comment>This is a comment</comment> | |
</data> | |
There are any number of "resheader" rows that contain simple | |
name/value pairs. | |
Each data row contains a name, and value. The row also contains a | |
type or mimetype. Type corresponds to a .NET class that support | |
text/value conversion through the TypeConverter architecture. | |
Classes that don't support this are serialized and stored with the | |
mimetype set. | |
The mimetype is used for serialized objects, and tells the | |
ResXResourceReader how to depersist the object. This is currently not | |
extensible. For a given mimetype the value must be set accordingly: | |
Note - application/x-microsoft.net.object.binary.base64 is the format | |
that the ResXResourceWriter will generate, however the reader can | |
read any of the formats listed below. | |
mimetype: application/x-microsoft.net.object.binary.base64 | |
value : The object must be serialized with | |
: System.Serialization.Formatters.Binary.BinaryFormatter | |
: and then encoded with base64 encoding. | |
mimetype: application/x-microsoft.net.object.soap.base64 | |
value : The object must be serialized with | |
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter | |
: and then encoded with base64 encoding. | |
mimetype: application/x-microsoft.net.object.bytearray.base64 | |
value : The object must be serialized into a byte array | |
: using a System.ComponentModel.TypeConverter | |
: and then encoded with base64 encoding. | |
--> | |
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | |
<xsd:element name="root" msdata:IsDataSet="true"> | |
<xsd:complexType> | |
<xsd:choice maxOccurs="unbounded"> | |
<xsd:element name="metadata"> | |
<xsd:complexType> | |
<xsd:sequence> | |
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | |
</xsd:sequence> | |
<xsd:attribute name="name" type="xsd:string" /> | |
<xsd:attribute name="type" type="xsd:string" /> | |
<xsd:attribute name="mimetype" type="xsd:string" /> | |
</xsd:complexType> | |
</xsd:element> | |
<xsd:element name="assembly"> | |
<xsd:complexType> | |
<xsd:attribute name="alias" type="xsd:string" /> | |
<xsd:attribute name="name" type="xsd:string" /> | |
</xsd:complexType> | |
</xsd:element> | |
<xsd:element name="data"> | |
<xsd:complexType> | |
<xsd:sequence> | |
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | |
</xsd:sequence> | |
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> | |
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | |
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | |
</xsd:complexType> | |
</xsd:element> | |
<xsd:element name="resheader"> | |
<xsd:complexType> | |
<xsd:sequence> | |
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |
</xsd:sequence> | |
<xsd:attribute name="name" type="xsd:string" use="required" /> | |
</xsd:complexType> | |
</xsd:element> | |
</xsd:choice> | |
</xsd:complexType> | |
</xsd:element> | |
</xsd:schema> | |
<resheader name="resmimetype"> | |
<value>text/microsoft-resx</value> | |
</resheader> | |
<resheader name="version"> | |
<value>2.0</value> | |
</resheader> | |
<resheader name="reader"> | |
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |
</resheader> | |
<resheader name="writer"> | |
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |
</resheader> | |
</root> |
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.Collections.ObjectModel; | |
namespace WpfValueTypeEditor { | |
public struct Point { | |
public int X { get; set; } | |
public int Y { get; set; } | |
} | |
public enum Direction | |
{ | |
Left, Right | |
} | |
public class RootModel { | |
public Direction Direction { get; set; } | |
public List<Direction> Directions { get; set; } | |
public Point Point { get; set; } | |
public ObservableCollection<Point> Points { get; set; } | |
public string String { get; set; } | |
public ObservableCollection<string> Strings { get; set; } | |
public RootModel() | |
{ | |
Directions = Enum.GetValues(typeof (Direction)).Cast<Direction>().ToList(); | |
Points = new ObservableCollection<Point>(); | |
Strings = new ObservableCollection<string>(); | |
Strings.CollectionChanged += Strings_CollectionChanged; | |
} | |
void Strings_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) | |
{ | |
} | |
} | |
} |
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
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// Runtime Version:4.0.30319.239 | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace WpfValueTypeEditor.Properties { | |
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] | |
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] | |
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { | |
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); | |
public static Settings Default { | |
get { | |
return defaultInstance; | |
} | |
} | |
} | |
} |
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
<?xml version='1.0' encoding='utf-8'?> | |
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)"> | |
<Profiles> | |
<Profile Name="(Default)" /> | |
</Profiles> | |
<Settings /> | |
</SettingsFile> |
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; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.Collections.Specialized; | |
using System.ComponentModel; | |
using System.Linq; | |
using System.Text; | |
namespace WpfValueTypeEditor | |
{ | |
public interface IValueRef : INotifyPropertyChanged | |
{ | |
object Value { get; set; } | |
} | |
public interface IValueRef<T> : INotifyPropertyChanged | |
{ | |
T Value { get; set; } | |
} | |
public class ListItemRef : IValueRef | |
{ | |
// FIXME weak reference | |
private IList list; | |
private int index; | |
public ListItemRef(IList list, int index) | |
{ | |
this.list = list; | |
this.index = index; | |
if (list is INotifyCollectionChanged) | |
{ | |
var notifyList = list as INotifyCollectionChanged; | |
// TODO use system notification manager or whatever it is called | |
// FIXME use weak reference | |
notifyList.CollectionChanged += notifyList_CollectionChanged; | |
} | |
} | |
void notifyList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) | |
{ | |
PropertyChanged(sender, new PropertyChangedEventArgs("Value")); | |
} | |
public object Value | |
{ | |
get { return list[index]; } | |
set | |
{ | |
var oldValue = list[index]; | |
// replace event does not work :( | |
//list[index] = value; | |
list.RemoveAt(index); | |
list.Insert(index, value); | |
PropertyChanged(this, new PropertyChangedEventArgs("Value")); | |
} | |
} | |
public event PropertyChangedEventHandler PropertyChanged = delegate { }; | |
} | |
public class ListItemRef<T> : IValueRef<T>, IValueRef | |
{ | |
private IList<T> list; | |
private int index; | |
public ListItemRef(IList<T> list, int index) | |
{ | |
this.list = list; | |
this.index = index; | |
} | |
public T Value | |
{ | |
get { return list[index]; } | |
set | |
{ | |
list[index] = value; | |
PropertyChanged(this, new PropertyChangedEventArgs("Value")); | |
} | |
} | |
public event PropertyChangedEventHandler PropertyChanged = delegate { }; | |
object IValueRef.Value | |
{ | |
get { return Value; } | |
set { Value = (T)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
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<PropertyGroup> | |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | |
<ProductVersion>8.0.30703</ProductVersion> | |
<SchemaVersion>2.0</SchemaVersion> | |
<ProjectGuid>{80D2478E-86E9-409F-92BA-3C106D02478A}</ProjectGuid> | |
<OutputType>WinExe</OutputType> | |
<AppDesignerFolder>Properties</AppDesignerFolder> | |
<RootNamespace>WpfValueTypeEditor</RootNamespace> | |
<AssemblyName>WpfValueTypeEditor</AssemblyName> | |
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |
<TargetFrameworkProfile>Client</TargetFrameworkProfile> | |
<FileAlignment>512</FileAlignment> | |
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | |
<PlatformTarget>x86</PlatformTarget> | |
<DebugSymbols>true</DebugSymbols> | |
<DebugType>full</DebugType> | |
<Optimize>false</Optimize> | |
<OutputPath>bin\Debug\</OutputPath> | |
<DefineConstants>DEBUG;TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | |
<PlatformTarget>x86</PlatformTarget> | |
<DebugType>pdbonly</DebugType> | |
<Optimize>true</Optimize> | |
<OutputPath>bin\Release\</OutputPath> | |
<DefineConstants>TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> | |
<DebugSymbols>true</DebugSymbols> | |
<OutputPath>bin\Debug\</OutputPath> | |
<DefineConstants>DEBUG;TRACE</DefineConstants> | |
<DebugType>full</DebugType> | |
<PlatformTarget>AnyCPU</PlatformTarget> | |
<CodeAnalysisLogFile>bin\Debug\WpfValueTypeEditor.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> | |
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> | |
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> | |
<ErrorReport>prompt</ErrorReport> | |
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> | |
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets> | |
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> | |
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules> | |
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> | |
</PropertyGroup> | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'"> | |
<OutputPath>bin\Release\</OutputPath> | |
<DefineConstants>TRACE</DefineConstants> | |
<Optimize>true</Optimize> | |
<DebugType>pdbonly</DebugType> | |
<PlatformTarget>AnyCPU</PlatformTarget> | |
<CodeAnalysisLogFile>bin\Release\WpfValueTypeEditor.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> | |
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> | |
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> | |
<ErrorReport>prompt</ErrorReport> | |
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> | |
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets> | |
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> | |
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules> | |
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> | |
</PropertyGroup> | |
<ItemGroup> | |
<Reference Include="System" /> | |
<Reference Include="System.Data" /> | |
<Reference Include="System.Xml" /> | |
<Reference Include="Microsoft.CSharp" /> | |
<Reference Include="System.Core" /> | |
<Reference Include="System.Xml.Linq" /> | |
<Reference Include="System.Data.DataSetExtensions" /> | |
<Reference Include="System.Xaml"> | |
<RequiredTargetFramework>4.0</RequiredTargetFramework> | |
</Reference> | |
<Reference Include="WindowsBase" /> | |
<Reference Include="PresentationCore" /> | |
<Reference Include="PresentationFramework" /> | |
</ItemGroup> | |
<ItemGroup> | |
<ApplicationDefinition Include="App.xaml"> | |
<Generator>MSBuild:Compile</Generator> | |
<SubType>Designer</SubType> | |
</ApplicationDefinition> | |
<Compile Include="BindingDecoratorBase.cs" /> | |
<Compile Include="ContentBindingExtension.cs" /> | |
<Compile Include="RootModel.cs" /> | |
<Compile Include="ValueRef.cs" /> | |
<Page Include="MainWindow.xaml"> | |
<Generator>MSBuild:Compile</Generator> | |
<SubType>Designer</SubType> | |
</Page> | |
<Compile Include="App.xaml.cs"> | |
<DependentUpon>App.xaml</DependentUpon> | |
<SubType>Code</SubType> | |
</Compile> | |
<Compile Include="MainWindow.xaml.cs"> | |
<DependentUpon>MainWindow.xaml</DependentUpon> | |
<SubType>Code</SubType> | |
</Compile> | |
</ItemGroup> | |
<ItemGroup> | |
<Compile Include="Properties\AssemblyInfo.cs"> | |
<SubType>Code</SubType> | |
</Compile> | |
<Compile Include="Properties\Resources.Designer.cs"> | |
<AutoGen>True</AutoGen> | |
<DesignTime>True</DesignTime> | |
<DependentUpon>Resources.resx</DependentUpon> | |
</Compile> | |
<Compile Include="Properties\Settings.Designer.cs"> | |
<AutoGen>True</AutoGen> | |
<DependentUpon>Settings.settings</DependentUpon> | |
<DesignTimeSharedInput>True</DesignTimeSharedInput> | |
</Compile> | |
<EmbeddedResource Include="Properties\Resources.resx"> | |
<Generator>ResXFileCodeGenerator</Generator> | |
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | |
</EmbeddedResource> | |
<None Include="Properties\Settings.settings"> | |
<Generator>SettingsSingleFileGenerator</Generator> | |
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | |
</None> | |
<AppDesigner Include="Properties\" /> | |
</ItemGroup> | |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |
Other similar extension points exist, see Microsoft.Common.targets. | |
<Target Name="BeforeBuild"> | |
</Target> | |
<Target Name="AfterBuild"> | |
</Target> | |
--> | |
</Project> |
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
| |
Microsoft Visual Studio Solution File, Format Version 11.00 | |
# Visual Studio 2010 | |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfValueTypeEditor", "WpfValueTypeEditor.csproj", "{80D2478E-86E9-409F-92BA-3C106D02478A}" | |
EndProject | |
Global | |
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |
Debug|Any CPU = Debug|Any CPU | |
Debug|x86 = Debug|x86 | |
Release|Any CPU = Release|Any CPU | |
Release|x86 = Release|x86 | |
EndGlobalSection | |
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Debug|Any CPU.Build.0 = Debug|Any CPU | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Debug|x86.ActiveCfg = Debug|x86 | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Debug|x86.Build.0 = Debug|x86 | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Release|Any CPU.ActiveCfg = Release|Any CPU | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Release|Any CPU.Build.0 = Release|Any CPU | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Release|x86.ActiveCfg = Release|x86 | |
{80D2478E-86E9-409F-92BA-3C106D02478A}.Release|x86.Build.0 = Release|x86 | |
EndGlobalSection | |
GlobalSection(SolutionProperties) = preSolution | |
HideSolutionNode = FALSE | |
EndGlobalSection | |
EndGlobal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment