承接上文
https://www.cnblogs.com/wandia/p/17084881.html
为了达到使用WrapPanel作为布局面板时候实现查询按钮靠右,又瞎搞了WrapPanel,实现
效果如下图,由于代码有Bug,请留言索要提取
/// <summary>
/// 2023-02-02
/// WrapPanel改进后,增加了填充式布局,转载请保留博客地址!
/// 2023-02-04
/// WrapPanel改进后,最后元素靠右布局
/// 来源:https://www.cnblogs.com/wandia/p/17084881.html
/// 作者:陈-林-赵-魏
/// WrapPanel改进,增加了设置元素宽度高度时候填充式铺满
/// 代码改自 Microsoft WrapPanel 源码
/// </summary>
public class WrapPanelFill : WrapPanel
{
public static readonly DependencyProperty UseToFillProperty = DependencyProperty.RegisterAttached("UseToFill",
typeof(bool),
typeof(WrapPanelFill),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
public static void SetUseToFill(UIElement element, bool value)
{
element.SetValue(UseToFillProperty, value);
}
public static bool GetUseToFill(UIElement element)
{
return (bool)element.GetValue(UseToFillProperty);
}
public bool IsAdaptiveLayout
{
get { return (bool)GetValue(IsAdaptiveLayoutProperty); }
set { SetValue(IsAdaptiveLayoutProperty, value); }
}
public static readonly DependencyProperty IsAdaptiveLayoutProperty =
DependencyProperty.Register("IsAdaptiveLayout", typeof(bool), typeof(WrapPanelFill), new UIPropertyMetadata(false, OnIsAdaptiveLayout_ProperthChanged));
private static void OnIsAdaptiveLayout_ProperthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
WrapPanelFill fill = d as WrapPanelFill;
if (fill != null) fill.InvalidateMeasure();
}
private const double DBL_EPSILON = 2.2204460492503131e-016; /* smallest such that 1.0+DBL_EPSILON != 1.0 */
private static bool DoubleAreClose(double value1, double value2)
{
//in case they are Infinities (then epsilon check does not work)
if (value1 == value2)
{
return true;
}
// This computes (|value1-value2| / (|value1| + |value2| + 10.0)) < DBL_EPSILON
double eps = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * DBL_EPSILON;
double delta = value1 - value2;
return -eps < delta && eps > delta;
}
private static bool DoubleGreaterThan(double value1, double value2)
{
return value1 > value2 && !DoubleAreClose(value1, value2);
}
private bool IsItemWidthSet { get { return !double.IsNaN(this.ItemWidth) && this.ItemWidth > 0; } }
private bool IsItemHeightSet { get { return !double.IsNaN(this.ItemHeight) && this.ItemHeight > 0; } }
protected override Size MeasureOverride(Size constraint)
{
UVSize uvConstraint = new UVSize(Orientation, constraint.Width, constraint.Height);
UVSize curLineSize = new UVSize(Orientation);
UVSize panelSize = new UVSize(Orientation);
Size childConstraint = GetConstraintSize(constraint);
return new Size(panelSize.Width, panelSize.Height);
}
private Size GetConstraintSize(Size constraint)
{
int visibleCount = this.InternalChildren.Cast<UIElement>().Count(p => p != null && p.Visibility != Visibility.Collapsed);
Size childConstraint = new Size(constraint.Width, constraint.Height);
if (IsItemWidthSet == true)
{
if (Orientation == Orientation.Horizontal && !double.IsInfinity(constraint.Width) && this.IsAdaptiveLayout == true)
{
var count = Math.Floor(constraint.Width / this.ItemWidth);
if (visibleCount >= count)
{
var averageWidth = constraint.Width / Math.Max(count, 1);
childConstraint.Width = Math.Max(averageWidth, this.ItemWidth);
}
else if (visibleCount > 0)
{
childConstraint.Width = constraint.Width / visibleCount;
}
}
else
{
childConstraint.Width = this.ItemWidth;
}
}
if (IsItemHeightSet == true)
{
if (Orientation == Orientation.Vertical && !double.IsInfinity(constraint.Height) && this.IsAdaptiveLayout == true)
{
var count = Math.Floor(constraint.Height / this.ItemHeight);
if (visibleCount >= count)
{
var averageHeight = constraint.Height / Math.Max(count, 1);
childConstraint.Height = Math.Max(averageHeight, this.ItemHeight);
}
else if (visibleCount > 0)
{
childConstraint.Height = constraint.Height / visibleCount;
}
}
else
{
childConstraint.Height = this.ItemHeight;
}
}
return childConstraint;
}
protected override Size ArrangeOverride(Size finalSize)
{
return finalSize;
}
private void arrangeLine(double v, double lineV, int start, int end, bool useItemU, double itemU, Size arrangeSize)
{
}
private struct UVSize
{
internal UVSize(Orientation orientation, double width, double height)
{
U = V = 0d;
_orientation = orientation;
Width = width;
Height = height;
}
internal UVSize(Orientation orientation)
{
U = V = 0d;
_orientation = orientation;
}
internal double U;
internal double V;
private Orientation _orientation;
internal double Width
{
get { return (_orientation == Orientation.Horizontal ? U : V); }
set { if (_orientation == Orientation.Horizontal) U = value; else V = value; }
}
internal double Height
{
get { return (_orientation == Orientation.Horizontal ? V : U); }
set { if (_orientation == Orientation.Horizontal) V = value; else U = value; }
}
}
}
窗体程序xaml代码如下:
<Window x:Class="WrapPanelFillDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WrapPanelFillDemo"
xmlns:Controls="clr-namespace:WrapPanelFillDemo"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<TextBlock Text="一个优化奇怪的WrapPanel" DockPanel.Dock="Top" FontWeight="Bold"/>
<TabControl>
<TabItem Header="示例1">
<TabControl>
<TabItem Header="情景1(高度充满)">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold" Text="元素宽度高度设置时 填充式 WrapPanel(陈-林-赵-魏)" Margin="0,5"/>
<WrapPanel Grid.Row="1" Margin="0,2">
<CheckBox x:Name="ChkAdaptiveLayout" IsChecked="True" Content="填充式布局"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Margin="0,0,50,0"/>
<CheckBox x:Name="ChkVertical" IsChecked="False" Content="垂直布局"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Margin="0,0,50,0"/>
<TextBlock Text="元素宽度" VerticalAlignment="Center"/>
<TextBox x:Name="txtItemWidth" MinWidth="120" Height="22" VerticalContentAlignment="Center"
Text="{Binding ElementName=WrapPanelFill,Path=ItemWidth,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="元素高度" VerticalAlignment="Center"/>
<TextBox x:Name="txtItemHeight" MinWidth="120" Height="22" VerticalContentAlignment="Center"
Text="{Binding ElementName=WrapPanelFill,Path=ItemHeight,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="输入NaN代表宽度不确定"/>
</WrapPanel>
<local:WrapPanelFill x:Name="WrapPanelFill" IsAdaptiveLayout="{Binding ElementName=ChkAdaptiveLayout,Path=IsChecked,Mode=TwoWay}" ItemWidth="150" Grid.Row="3"
Orientation="Horizontal" >
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#F05033" Width="4"/>
<Grid Margin="5">
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFB8B2B2" />
</Grid>
<TextBlock Text="Changed" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#F05033" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFDCA1A1" />
</Grid>
<TextBlock Text="Branches" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF3333F0" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFB5B9BD" />
</Grid>
<TextBlock Text="Sync" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF616161" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FF3E3E3E" />
</Grid>
<TextBlock Text="Setting" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FF555E85" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF616161" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FF93B6AA" />
</Grid>
<TextBlock Text="Others" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
</local:WrapPanelFill>
<Border Grid.Row="3" BorderThickness="1" BorderBrush="Red" Margin="0,4" Visibility="Collapsed">
<Label Content="这里是VS扩展git源码提交部分界面不实现!"/>
</Border>
</Grid>
</TabItem>
<TabItem Header="情景2(高度Auto)">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold" Text="元素宽度高度设置时 填充式 WrapPanel(陈-林-赵-魏)" Margin="0,5"/>
<WrapPanel Grid.Row="1" Margin="0,2">
<CheckBox x:Name="ChkAdaptiveLayout2" IsChecked="True" Content="填充式布局"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Margin="0,0,50,0"/>
<CheckBox x:Name="ChkVertical2" IsChecked="False" Content="垂直布局"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Margin="0,0,50,0"/>
<TextBlock Text="元素宽度" VerticalAlignment="Center"/>
<TextBox x:Name="txtItemWidth2" MinWidth="120" Height="22" VerticalContentAlignment="Center"
Text="{Binding ElementName=WrapPanelFill2,Path=ItemWidth,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="元素高度" VerticalAlignment="Center"/>
<TextBox x:Name="txtItemHeight2" MinWidth="120" Height="22" VerticalContentAlignment="Center"
Text="{Binding ElementName=WrapPanelFill2,Path=ItemHeight,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
</WrapPanel>
<local:WrapPanelFill x:Name="WrapPanelFill2" IsAdaptiveLayout="{Binding ElementName=ChkAdaptiveLayout2,Path=IsChecked,Mode=TwoWay}" ItemWidth="150" Grid.Row="2"
Orientation="Horizontal" ItemHeight="40">
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#F05033" Width="4"/>
<Grid Margin="5">
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFB8B2B2" />
</Grid>
<TextBlock Text="Changed" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#F05033" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFDCA1A1" />
</Grid>
<TextBlock Text="Branches" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF3333F0" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFB5B9BD" />
</Grid>
<TextBlock Text="Sync" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF616161" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FF3E3E3E" />
</Grid>
<TextBlock Text="Setting" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FF555E85" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF616161" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FF93B6AA" />
</Grid>
<TextBlock Text="Others" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
</local:WrapPanelFill>
<Border Grid.Row="3" BorderThickness="1" BorderBrush="Red" Margin="0,4" Visibility="Visible">
<Label Content="这里是VS扩展git源码提交部分界面不实现!"/>
</Border>
</Grid>
</TabItem>
<TabItem Header="情景3(ScrollView中表现)">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold" Text="元素宽度高度设置时 填充式 WrapPanel(陈-林-赵-魏)" Margin="0,5"/>
<WrapPanel Grid.Row="1" Margin="0,2">
<CheckBox x:Name="ChkAdaptiveLayout3" IsChecked="True" Content="填充式布局"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Margin="0,0,50,0"/>
<CheckBox x:Name="ChkVertical3" IsChecked="False" Content="垂直布局"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Margin="0,0,50,0"/>
<TextBlock Text="元素宽度" VerticalAlignment="Center"/>
<TextBox x:Name="txtItemWidth3" MinWidth="120" Height="22" VerticalContentAlignment="Center"
Text="{Binding ElementName=WrapPanelFill3,Path=ItemWidth,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="元素高度" VerticalAlignment="Center"/>
<TextBox x:Name="txtItemHeight3" MinWidth="120" Height="22" VerticalContentAlignment="Center"
Text="{Binding ElementName=WrapPanelFill3,Path=ItemHeight,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="输入NaN代表宽度不确定"/>
</WrapPanel>
<Border Grid.Row="3" Margin="40" BorderBrush="Red" BorderThickness="1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<local:WrapPanelFill x:Name="WrapPanelFill3" IsAdaptiveLayout="{Binding ElementName=ChkAdaptiveLayout3,Path=IsChecked,Mode=TwoWay}" ItemWidth="150" Grid.Row="3"
Orientation="Horizontal" >
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#F05033" Width="4"/>
<Grid Margin="5">
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFB8B2B2" />
</Grid>
<TextBlock Text="Changed" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#F05033" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFDCA1A1" />
</Grid>
<TextBlock Text="Branches" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF3333F0" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FFB5B9BD" />
</Grid>
<TextBlock Text="Sync" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FFCFCFCF" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF616161" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FF3E3E3E" />
</Grid>
<TextBlock Text="Setting" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
<DockPanel MinHeight="35" Margin="0,0,5,2">
<DockPanel.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFA6A6A6" Offset="0"/>
<GradientStop Color="#FF555E85" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Rectangle Fill="#FF616161" Width="4"/>
<Grid Margin="5" >
<Ellipse StrokeThickness="2" Width="25" Height="25" Stroke="Black"/>
<Ellipse StrokeThickness="2" Width="17" Height="17" Fill="#FF93B6AA" />
</Grid>
<TextBlock Text="Others" FontWeight="Medium" FontSize="16" VerticalAlignment="Center"/>
</DockPanel>
</local:WrapPanelFill>
</ScrollViewer>
</Border>
</Grid>
</TabItem>
</TabControl>
</TabItem>
<TabItem Header="示例2">
<DockPanel>
<TextBlock Text="查询控件排列优化" DockPanel.Dock="Top" FontWeight="Bold"/>
<TextBlock Text="强迫查询按钮向右停靠" DockPanel.Dock="Top"/>
<TabControl>
<TabItem Header="普通">
<StackPanel>
<Label Content="WrapPanel" Background="#FFCBCBEA"/>
<WrapPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid VerticalAlignment="Center" Margin="5,0" Rows="1" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</WrapPanel>
<Label Content="WrapPanelFill" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid VerticalAlignment="Center" Margin="5,0" Rows="1" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
</StackPanel>
</TabItem>
<TabItem Header="普通+填充式">
<StackPanel>
<Label Content="WrapPanel" Background="#FFCBCBEA"/>
<WrapPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid VerticalAlignment="Center" Margin="5,0" Rows="1" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</WrapPanel>
<Label Content="WrapPanelFill" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2" Width="100">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid VerticalAlignment="Center" Margin="5,0" Rows="1" MinWidth="200" Controls:WrapPanelFill.UseToFill="True">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
</StackPanel>
</TabItem>
<TabItem Header="ItemWidth">
<StackPanel>
<Label Content="WrapPanel" Background="#FFCBCBEA"/>
<WrapPanel ItemWidth="110">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</WrapPanel>
<Label Content="WrapPanelFill" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill ItemWidth="110">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
</StackPanel>
</TabItem>
<TabItem Header="ItemWidth+填充式">
<StackPanel>
<Label Content="WrapPanel" Background="#FFCBCBEA"/>
<WrapPanel ItemWidth="110">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</WrapPanel>
<Label Content="WrapPanelFill" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill ItemWidth="110">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200" Controls:WrapPanelFill.UseToFill="True">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
</StackPanel>
</TabItem>
<TabItem Header="ItemWidth+适应式布局">
<StackPanel>
<Label Content="WrapPanel" Background="#FFCBCBEA"/>
<WrapPanel ItemWidth="110">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</WrapPanel>
<Label Content="WrapPanelFill" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill ItemWidth="110" IsAdaptiveLayout="True">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
</StackPanel>
</TabItem>
<TabItem Header="ItemWidth+填充式+适应式布局">
<StackPanel>
<Label Content="WrapPanel" Background="#FFCBCBEA"/>
<WrapPanel ItemWidth="110">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</WrapPanel>
<Label Content="WrapPanelFill" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill ItemWidth="110" IsAdaptiveLayout="True">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200"
Controls:WrapPanelFill.UseToFill="True">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
<Label Content="WrapPanelFill Demo2" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill ItemWidth="110" IsAdaptiveLayout="True">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200"
Controls:WrapPanelFill.UseToFill="True" HorizontalAlignment="Center">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
<Label Content="WrapPanelFill Demo3" Background="#FFB4F1AA"/>
<Controls:WrapPanelFill ItemWidth="110" IsAdaptiveLayout="True">
<DockPanel Margin="0,2">
<TextBlock Text="内容1" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容2" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容3" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容4" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容5" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<DockPanel Margin="0,2">
<TextBlock Text="内容6" VerticalAlignment="Center"/>
<TextBox Height="23"/>
</DockPanel>
<UniformGrid Rows="1" VerticalAlignment="Center" Margin="5,0" MinWidth="200"
Controls:WrapPanelFill.UseToFill="True" HorizontalAlignment="Right">
<Button Content="查询" Height="22" Margin="1"/>
<Button Content="导出" Height="22" Margin="1"/>
</UniformGrid>
</Controls:WrapPanelFill>
</StackPanel>
</TabItem>
</TabControl>
</DockPanel>
</TabItem>
</TabControl>
</DockPanel>
</Window>
标签:return,Orientation,constraint,改造,Height,Width,固板,double
From: https://www.cnblogs.com/wandia/p/17092221.html