How to bind a read-only WPF control property (eg ActualWidth) so its value is accessible in the view model? [duplicate] How to bind a read-only WPF control property (eg ActualWidth) so its value is accessible in the view model? [duplicate] wpf wpf

How to bind a read-only WPF control property (eg ActualWidth) so its value is accessible in the view model? [duplicate]


The actual problem as to why this is not working is described here.

However, the given solution to create a throwing setter to pass the validation would not work in your case.

I think it's ok to call a method on the ViewModel. If that's the code behind part that bugs you, perhaps you can use interactivity to call a method based on an event trigger (SizeChanged).


do you really need a binding for that?

    class MyVM    {        FrameworkElement _context;        public MyVM(FrameworkElement context)        {            _context = context;        }        public double Width        {            get { return _context.ActualWidth; }        }    }