WPF 改进 WrapPanel 右侧填充

本文经原作者授权以原创方式二次分享,欢迎转载、分享。

WPF 改进 WrapPanel 右边缘填充

作者:陈-林-赵-魏|驚鏵

原文链接[1]:https://www.cnblogs.com/wandia/p/17084881.html

  • 目的:改进下WrapPanel, 多实现一个空间超出时候的充满效果,可以参考VSTeamgit面板的那个,实现一个 类似git提交代码 最后一个item充满整行的效果。

1) WrapPanelFill.cs 代码如下:

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Linq;
using System.Collections;
using System.Collections.Generic;namespace WrapPanelFillDemo
{/// <summary>    /// 2023-02-02/// WrapPanel改进后,增加了填充式布局,转载请保留博客地址!/// 来源:https://www.cnblogs.com/wandia/p/17084881.html/// 作者:陈-林-赵-魏/// WrapPanel改进,增加了设置元素宽度高度时候填充式铺满/// 代码改自 Microsoft WrapPanel 源码/// </summary>public class WrapPanelFill : WrapPanel{#region 依赖属性 是否填充式布局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();}#endregion#region 浮点数比较静态方法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_EPSILONdouble 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);}#endregion#region 是否设置元素宽度高度private bool IsItemWidthSet { get { return !double.IsNaN(this.ItemWidth) && this.ItemWidth > 0; } }private bool IsItemHeightSet { get { return !double.IsNaN(this.ItemHeight) && this.ItemHeight > 0; } }#endregion#region MeasureOverride/// <summary>///     <see cref="FrameworkElement.MeasureOverride" />/// </summary>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);UIElementCollection children = InternalChildren;for (int i = 0, count = children.Count; i < count; i++){UIElement child = children[i];if (child == null) continue;//Flow passes its own constrint to childrenchild.Measure(childConstraint);//this is the size of the child in UV spaceUVSize sz = new UVSize(Orientation,(IsItemWidthSet ? childConstraint.Width : child.DesiredSize.Width),(IsItemHeightSet ? childConstraint.Height : child.DesiredSize.Height));if (DoubleGreaterThan(curLineSize.U + sz.U, uvConstraint.U)){   //need to switch to another linepanelSize.U = Math.Max(curLineSize.U, panelSize.U);panelSize.V += curLineSize.V;curLineSize = sz;if (DoubleGreaterThan(sz.U, uvConstraint.U)){   //the element is wider then the constrint - give it a separate line panelSize.U = Math.Max(sz.U, panelSize.U);panelSize.V += sz.V;curLineSize = new UVSize(Orientation);  //用于存放全新1行狂赌}}else{//continue to accumulate a linecurLineSize.U += sz.U;curLineSize.V = Math.Max(sz.V, curLineSize.V);}}//the last line size, if any should be addedpanelSize.U = Math.Max(curLineSize.U, panelSize.U);panelSize.V += curLineSize.V;//go from UV space to W/H spacereturn 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 = averageWidth;}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 = averageHeight;}else if (visibleCount > 0){childConstraint.Height = constraint.Height / visibleCount;}}else{childConstraint.Height = this.ItemHeight;}}return childConstraint;}#endregion#region ArrangeOverride/// <summary>///     <see cref="FrameworkElement.ArrangeOverride" />/// </summary>protected override Size ArrangeOverride(Size finalSize){int firstInLine = 0;double accumulatedV = 0;UVSize uvConstraint = new UVSize(Orientation, finalSize.Width, finalSize.Height);UVSize curLineSize = new UVSize(Orientation);Size childConstraint = GetConstraintSize(finalSize);bool useItemU = (Orientation == Orientation.Horizontal ? IsItemWidthSet : IsItemHeightSet);double itemU = (Orientation == Orientation.Horizontal ? childConstraint.Width : childConstraint.Height);UIElementCollection children = InternalChildren;for (int i = 0, count = children.Count; i < count; i++){UIElement child = children[i];if (child == null) continue;UVSize sz = new UVSize(Orientation,(IsItemWidthSet ? childConstraint.Width : child.DesiredSize.Width),(IsItemHeightSet ? childConstraint.Height : child.DesiredSize.Height));if (DoubleGreaterThan(curLineSize.U + sz.U, uvConstraint.U)){    //need to switch to another linearrangeLine(accumulatedV, curLineSize.V, firstInLine, i, useItemU, itemU);accumulatedV += curLineSize.V;curLineSize = sz;if (DoubleGreaterThan(sz.U, uvConstraint.U)) //the element is wider then the constraint - give it a separate line{//switch to next line which only contain one elementarrangeLine(accumulatedV, sz.V, i, ++i, useItemU, itemU);accumulatedV += sz.V;curLineSize = new UVSize(Orientation);}firstInLine = i;}else{   //continue to accumulate a linecurLineSize.U += sz.U;curLineSize.V = Math.Max(sz.V, curLineSize.V);}}//arrange the last line, if anyif (firstInLine < children.Count){arrangeLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU);}return finalSize;}private void arrangeLine(double v, double lineV, int start, int end, bool useItemU, double itemU){double u = 0;bool isHorizontal = (Orientation == Orientation.Horizontal);UIElementCollection children = InternalChildren;for (int i = start; i < end; i++){UIElement child = children[i];if (child != null){UVSize childSize = new UVSize(Orientation, child.DesiredSize.Width, child.DesiredSize.Height);double layoutSlotU = (useItemU ? itemU : childSize.U);child.Arrange(new Rect((isHorizontal ? u : v),(isHorizontal ? v : u),(isHorizontal ? layoutSlotU : lineV),(isHorizontal ? lineV : layoutSlotU)));u += layoutSlotU;}}}#endregion#region Private Structprivate 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; }}}#endregion}
}

2) MainWindow.xaml 代码如下:

<ws: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:ws="https://github.com/WPFDevelopersOrg/WPFDevelopers"xmlns:local="clr-namespace:WrapPanelFillDemo"mc:Ignorable="d"Title="Team Explorer-Home" Height="414" Width="324"><Window.Resources><Style TargetType="TextBlock"><Setter Property="VerticalAlignment" Value="Center"/><Setter Property="Margin" Value="2 0"/></Style></Window.Resources><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" VerticalContentAlignment="Center"Text="{Binding ElementName=WrapPanelFill,Path=ItemWidth,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/><TextBlock Text="元素高度" VerticalAlignment="Center"/><TextBox x:Name="txtItemHeight" MinWidth="120"  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"  VerticalContentAlignment="Center"Text="{Binding ElementName=WrapPanelFill2,Path=ItemWidth,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/><TextBlock Text="元素高度" VerticalAlignment="Center"/><TextBox x:Name="txtItemHeight2" MinWidth="120"  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"  VerticalContentAlignment="Center"Text="{Binding ElementName=WrapPanelFill3,Path=ItemWidth,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/><TextBlock Text="元素高度" VerticalAlignment="Center"/><TextBox x:Name="txtItemHeight3" MinWidth="120"  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>
</ws:Window>

参考资料

[1]

原文链接: https://www.cnblogs.com/wandia/p/17084881.html

WPF 改进 WrapPanel 右侧填充相关推荐

  1. pandas使用pad函数向dataframe特定数据列的每个字符串添加后置(后缀)补齐字符或者字符串、向所有字符串的右侧填充、直到宽度达到指定要求(right padding)

    pandas使用pad函数向dataframe特定数据列的每个字符串添加后置(后缀)补齐字符或者字符串.向所有字符串的右侧填充.直到宽度达到指定要求(right padding) 目录

  2. WPF 用代码实现WrapPanel右侧自动对齐(解决多余空白问题)

    未处理前效果: 处理后效果: <Border Background="{StaticResource BorderBg}" BorderThickness="2&q ...

  3. WPF中WrapPanel、StackPanel等添加滚动条ScrollViewer

    wpf中,在控件中直接设置ScrollViewer.HorizontalScrollBarVisibility和ScrollViewer.VerticalScrollBarVisibility属性,并 ...

  4. 【TensorFlow2.0】(7) 张量排序、填充、复制、限幅、坐标选择

    各位同学好,今天和大家分享一下TensorFlow2.0中的一些操作.内容有: (1)排序 tf.sort().tf.argsort().top_k():(2)填充 tf.pad():(3)复制 tf ...

  5. 多边形区域填充算法--扫描线种子填充算法

    分享一下我老师大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow http://bl ...

  6. opencv 图像填充

    定义pad_image_stride函数,将图像的长和宽填充到可以被指定整数整除.这个整数倍通常定义为stride. 一.opencv关键函数 opencv关键函数:cv2.copyMakeBorde ...

  7. 【Algorithm】种子填充算法

    转载:https://www.cnblogs.com/icmzn/p/5065306.html [平面区域填充算法]是计算机图形学领域的一个很重要的算法,区域填充即给出一个区域的边界 (也可以是没有边 ...

  8. html如何设置填充,CSS填充距离怎么设置?

    CSS将HTML中所有的元素都认为是一个"盒子",并把这个"盒子"分为了三个组成部分,这三个组成部分分别叫做"填充"."边界&qu ...

  9. mysql 字符串填充_mysql LPAD 和RPAD不足位数补齐填充函数

    MySQL填充字符串的函数LPAD(s1,len,s2) LPAD(s1,len,s2)函数将字符串s2填充到s1的开始处,使字符串的长度达到len,然后返回字符串s1.如果字符串s1的长度大于len ...

最新文章

  1. UVA 116 Unidirectional TSP DP
  2. Realtek 8192cu 支持 Android Hotspot
  3. 深度思考 | 从BERT看大规模数据的无监督利用
  4. 图文解说:Discuz论坛基础设置第一弹
  5. HP/Aruba 2620系列交换机DHCP中继配置方法
  6. HashMap遍历方式
  7. 【器件知识】【设计】ESD专题-闩锁效应-大尺寸输出缓冲器
  8. 教你从redhat官网获取ISO镜像
  9. PID参数整定——Z-N方法
  10. 风笑天社会研究方法第5版笔记和课后答案
  11. 水果店的售价应该怎么来定,水果店怎样确定价格
  12. PyTorch是什么?PyTorch有什么用?
  13. 百战RHCE(第一战:Linux基础命令1)
  14. 远程桌面 连接栏不见无法退出
  15. 如何将动图中多余的去掉?教你快速裁剪动图
  16. error pulling image configuration
  17. 我觉得是全网最全最好最有用的sed命令详解+示例
  18. Wi-Fi Display协议介绍
  19. php rtmp服务器搭建,rtmp直播服务器的搭建(小白踩坑)
  20. ACW95 费解的开关

热门文章

  1. java并发编程实战wwj----------------------第二阶段-------读写锁-------16-17-18
  2. thinkphp网站提示缓存文件写入失败
  3. 记录使用 Vue 过程中遇到的一些技术点
  4. 无胁科技-TVD每日漏洞情报-2022-10-24
  5. 我拿到了梦寐以求的字节跳动和腾讯双offer!知乎上转疯了!
  6. 杭州城西科创大走廊管委会副主任一行莅临谐云实地调研
  7. EQ、NE、GT、LT、GE、LE分别代表含义
  8. python 3d打印_基于Python的结构拓扑优化与3D打印试验研究
  9. UnicodeEncodeError: 'gbk' codec can't encode character '\u200b' in position 0: illegal multibyte seq
  10. Modbus 协议基础