Binding Setting Property but UI not updating. Can I debug within referenced project/control?

后端 未结 1 1542
走了就别回头了
走了就别回头了 2020-12-20 06:58

I have a custom control with bindings like below


    

        
1条回答
  •  隐瞒了意图╮
    2020-12-20 07:37

    After reading Kent Boogaart's answer to this question I think that the right place to change SetValue to SetCurrentValue isn't in the CLR Property but in the constructor for MarkDownEditor.

    public MarkdownEditor()
    {
        InitializeComponent();
        //Options = new MarkdownEditorOptions();
        this.SetCurrentValue(OptionsProperty, new MarkdownEditorOptions());
        DataContext = this;
    }
    

    In fact, this will work just as good without this.SetCurrentValue also since Options will be set through the Binding.

    To verify that your Binding has in fact been overwritten by SetValue you can add this code in some event for TabUsage (e.g PreviewMouseRightButtonDown for the FontSize TextBox) and the Binding will start to work again.

    private void TextBox_PreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        MarkdownEditor.MarkdownEditor editor = VisualTreeHelpers.GetVisualChild(this);
        Binding binding = new Binding();
        binding.Path = new PropertyPath("Options");
        binding.Source = this;
        binding.Mode = BindingMode.TwoWay;
        editor.SetBinding(MarkdownEditor.MarkdownEditor.OptionsProperty, binding);
    }
    

    0 讨论(0)
提交回复
热议问题