public PostViewModel(Post post) { internal_post = post; // Forward all notifications from internal object internal_post.PropertyChanged += (sender, args) => NotifyPropertyChanged(args.PropertyName); // Add an existing property var property = internal_post.GetType().GetProperty("Text"); custom_type.AddProperty(new CustomPropertyInfo(internal_post, property)); // Add dependency internal_post.PropertyChanged += (sender, args) => { if (args.PropertyName == "Text") NotifyPropertyChanged("ModifiedText"); }; // Create and add a new property //var expr_property = new ExpressionPropertyInfo<Post, string>("ModifiedText"); //expr_property.internal_object = internal_post; //Expression<Func<Post, string>> expr = (p) => p.Text + " modified"; //expr_property.GetFunc = expr.Compile(); //custom_type.AddProperty(expr_property); var expr_property = new ExpressionPropertyInfo<string>("ModifiedText"); Expression<Func<string>> expr = () => internal_post.Text + " modified"; expr_property.GetFunc = expr.Compile(); custom_type.AddProperty(expr_property); }
public MainWindow() { InitializeComponent(); m = new Post(); vm = new PostViewModel(m); DataContext = vm; }