如果将样本窗口排在上的项目栏下,则理事会将更新几秒的布局,直到所有栏目最终都有正确的宽度(与下期项目组完全相同)。
您可以改变窗户的宽度,从横向和纵向的角度来看待电梯的下层项目。 但是,一旦你改变窗户的高度,布局将分数秒钟。
注:在电网对地面积进行无限更新的其他问题中,没有像模糊不清之处。
我是否做过错——如果是的话,我如何能够确定这一点? ——或者我是否将这一问题留给微软公司处理?
背后法典:
namespace DynamicGridColumnBinding
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
public partial class MainWindow
{
private static readonly CultureInfo[] cultureInfos =
CultureInfo.GetCultures(CultureTypes.NeutralCultures).Take(15).ToArray();
public MainWindow()
{
this.InitializeComponent();
}
public static IEnumerable<CultureInfo> AllCultures
{
get { return cultureInfos; }
}
private void GridInitialized(object sender, EventArgs e)
{
var grid = (Grid)sender;
for ( int i = 0; i < cultureInfos.Length; i++ )
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto,
SharedSizeGroup = "g" + i,
});
}
private void ScrollViewerScrollChanged(object sender, ScrollChangedEventArgs e)
{
if ( e.HorizontalChange != 0 )
this.legendScroller.ScrollToHorizontalOffset(e.HorizontalOffset);
}
}
}
Xaml:
<FrameworkElement.Resources>
<ItemsPanelTemplate x:Key="panelTemplate">
<Grid Initialized="GridInitialized" />
</ItemsPanelTemplate>
<Style TargetType="ContentPresenter" x:Key="containerStyle">
<Setter Property="Tag" Value="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" />
<Setter Property="Grid.Column" Value="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" />
</Style>
<Style TargetType="TextBlock" x:Key="textStyle">
<Setter Property="Padding" Value="5" />
<Setter Property="Background" Value="Lime" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</FrameworkElement.Resources>
<DockPanel Grid.IsSharedSizeScope="True" DataContext="{Binding Source={x:Static local:MainWindow.AllCultures}}">
<ScrollViewer DockPanel.Dock="Top" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled"
x:Name="legendScroller">
<ItemsControl ItemsSource="{Binding}" AlternationCount="{x:Static System:Int32.MaxValue}" Margin="0 0 500 0"
ItemsPanel="{StaticResource panelTemplate}" ItemContainerStyle="{StaticResource containerStyle}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type glob:CultureInfo}">
<GroupBox Header="{Binding Name}" HeaderStringFormat="[ {0} ]">
<TextBlock Style="{StaticResource textStyle}"
Text="{Binding Tag, RelativeSource={RelativeSource AncestorType=ContentPresenter, AncestorLevel=2}}" />
</GroupBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<TextBlock Foreground="Red" DockPanel.Dock="Top" Margin="0 10" FontSize="20" Text="some random arbitrary content in between" />
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto" ScrollChanged="ScrollViewerScrollChanged">
<ItemsControl ItemsSource="{Binding}" AlternationCount="{x:Static System:Int32.MaxValue}"
ItemsPanel="{StaticResource panelTemplate}" ItemContainerStyle="{StaticResource containerStyle}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type glob:CultureInfo}">
<Border Background="DodgerBlue" Padding="5" Margin="1">
<GroupBox Header="{Binding DisplayName}">
<TextBlock Style="{StaticResource textStyle}" Padding="5 100"
Text="{Binding Tag, RelativeSource={RelativeSource AncestorType=ContentPresenter, AncestorLevel=2}}" />
</GroupBox>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
BTW:如果你把上项“Control”项目的规模(通过在Box集团中添加MinWidth=“200”
),那么下项“Control”将 act。
BTW2:从 app开始。 8个共用大小栏目(样本有15个,由<代码>.Take(15)控制),你看到重整出现,每个栏目的时间翻一番——这样20个栏几乎一分钟。
BTW3: 在3个月中没有收到任何意见,令人沮丧。