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

十年热恋 提交于 2019-11-29 01:10:16
sowee15

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; }
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!