Adding a linebreak/new line to a WPF Wrap Panel

允我心安 提交于 2019-11-30 07:00:13

This is a line break in a WrapPanel:

<WrapPanel>
    <TextBlock Text="&#xD;"/>
</WrapPanel>

Update

I think I figured out what you're trying to ask. If you have a WrapPanel that is laying out by row, and you want to force it to the next row, you can replace the single WrapPanel with

 <StackPanel Orientation="Vertical">
  <StackPanel Orientation="Horizontal">
   <!-- items -->
  </StackPanel>
  <StackPanel Orientation="Horizontal">
   <!-- items -->
  </StackPanel>
  <StackPanel Orientation="Horizontal">
   <!-- items -->
  </StackPanel>
 </StackPanel>

If you want to preserve wrapping of individual rows, you can use WrapPanels inside the vertical StackPanel.

public class NewLine : FrameworkElement
{
    public NewLine()
    {
        Height = 0;
        var binding = new Binding
        {
            RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(WrapPanel), 1),
            Path = new PropertyPath("ActualWidth")
        };
        BindingOperations.SetBinding(this, WidthProperty, binding);
    }
}

<WrapPanel>
    <TextBox Text="Text1"/>
    <TextBox Text="Text2"/>
    <my:NewLine/>
    <TextBox Text="Text3"/>
    <TextBox Text="Text4"/>
</WrapPanel>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!