binding to width property in code behind

后端 未结 2 1060
一整个雨季
一整个雨季 2020-12-19 10:17

I have a situation where I need to create View box with one button. The xaml for this is as below: Please observe Width property of viewbox. The Width should be increased/de

相关标签:
2条回答
  • 2020-12-19 10:33

    This should do what you want:

    Viewbox x = new Viewbox();
    Binding bnd = new Binding("Value") { ElementName = "ZoomSlider"};
    BindingOperations.SetBinding(x, Viewbox.WidthProperty, bnd);
    // ... Code to insert the Viewbox into the WrapPanel etc.
    
    0 讨论(0)
  • 2020-12-19 10:36

    You can create the binding relatively easily in Code Behind:

    var widthBinding = new Binding("Value") { ElementName = "ZoomSlider" };
    
    _ScaleButton.SetBinding(FrameworkElement.WidthProperty, widthBinding);
    
    0 讨论(0)
提交回复
热议问题