예제 #1
0
        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);
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();

              m = new Post();
              vm = new PostViewModel(m);

              DataContext = vm;
        }