有谁知道甚至可以在WPF Wrap面板中输入换行符?它违背了包装面板的用途,所以我不确定它是否可行.
如果不是,是否有任何其他WPF控件实际上允许我输入换行符并支持添加childern(我自己的自定义控件?)
Jay*_*Jay 15
这是一个换行符WrapPanel:
<WrapPanel>
<TextBlock Text="
"/>
</WrapPanel>
Run Code Online (Sandbox Code Playgroud)
我想我弄清楚你要问的是什么.如果你有一个WrapPanel由行铺设,并希望将其强制到下一行,你可以取代单WrapPanel用
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<!-- items -->
</StackPanel>
<StackPanel Orientation="Horizontal">
<!-- items -->
</StackPanel>
<StackPanel Orientation="Horizontal">
<!-- items -->
</StackPanel>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
如果要保留单个行的换行,可以WrapPanel在垂直内部使用s StackPanel.
小智 13
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>
Run Code Online (Sandbox Code Playgroud)