Change margin programmatically in WPF / C#

前端 未结 4 963
忘掉有多难
忘掉有多难 2020-12-16 08:47

For this xaml:


How can I change the web browser control margin on top to be -5 progra

相关标签:
4条回答
  • 2020-12-16 09:25

    You can access the control from code behind using the Name property. In this case, test.Margin property can be used to change it dynamically.

    Margin is set as thickness, so the solution could be:

    test.Margin = new Thickness(0,-5,0,0);
    

    Note: Thickness have 4 parameters viz left, top, right and bottom. In above solution, we have just changed top margin, rest remained unchanged.

    0 讨论(0)
  • 2020-12-16 09:32
    test.Margin = new Thickness(0, 0, 0, 0);
    
    0 讨论(0)
  • 2020-12-16 09:37
    test.Margin = new Thickness(-5);
    
    0 讨论(0)
  • 2020-12-16 09:51
    test.Margin = new Thickness(0, -5, 0, 0);
    

    Alignment, Margins and Padding Overview (MSDN)
    FrameworkElement.Margin (MSDN)

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