質問
私はListBox
でPopupControl
を持っています。問題はスクロールしながら、ポップアップがリサイズするということです
実際の最も広い要素をフィットします。
私はこのサイズ変更を回避し、リスト全体で最も幅広い要素に自動的に調整できますか?
私はGrid
ではなく、成功せず、それを入れてみました。
解決
あなたは上の仮想維持したい場合は、定数にPopup.Width
を設定することができます。
もちろん、右の定数を選択するには、各ListBoxItem
があること、および最大を選択する方法を広い計算する(あるいは少なくとも推測)する必要があります。 ...通常、それはあなたのコンテンツに基づいて、ラフな推測を取得するにはあまりにも難しいことではありません。
他のヒント
OKこれが解決策です:
このプロパティを追加します<ListBox VirtualizingStackPanel.IsVirtualizing="False"
サイズ変更は、現在パネルは、すべての要素が含まれているため、停止して幅が調整されます 最も幅の広いものを尊重します。 仮想化するパネルを使用すると、それが表示された項目の一部だけだとListBoxのは、実際に目に見える最も広い要素にwidhtを調整します。
Disadvantadeたちはパネルの仮想化の使用しないこと、であるのもう(上のデフォルトである)
私は上記のようにまったく同じ問題に遭遇している - それはサイズ変更可能なポップアップコントロール内にレイアウトする多忙になるので、私のリストボックスには、仮想化しないだろう。私が見つけた解決策はMaxWidth
が含まれているグリッドのMaxHeight
とListBox
を制限することです。マイPopUp
コントロールはまだグリップとサイズ変更が可能である - それは取ることができた空間でそのわずか無制限ではない - 私はthatsのは、この問題を修正することができます知られたら実装する簡単な解決策を終了思う: - )
私は約18,000要素を持つクエリが1〜2秒の代わりに、30〜60秒で答えてスクロールが速い代わりに凍結されているのでListBox
が仮想化されて知っています。
<Popup x:Name="PART_Popup"
AllowsTransparency="true"
PlacementTarget="{Binding ElementName=PART_ContentHost}"
Placement="Bottom"
IsOpen="{Binding IsPopupOpened, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="None"
Focusable="False"
StaysOpen="True"
>
<Border BorderBrush="{TemplateBinding PopupBorderBrush}"
BorderThickness="{TemplateBinding PopupBorderThickness}"
Background="{DynamicResource {x:Static reskeys:ResourceKeys.ControlPopupBackgroundBrushKey}}"
>
<!-- Do NOT REMOVE MaxHeight and MaxWidth
These ensure that containing ListBox is virtualizing -->
<Grid x:Name="PART_ResizeableGrid" Background="Transparent"
MaxHeight="600"
MaxWidth="600"
>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border
x:Name="DropDownBorder"
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
Width="{Binding ActualWidth, ElementName=PART_ContentHost}"
Height="{Binding ActualHeight, ElementName=PART_ContentHost}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.RowSpan="2"
BorderThickness="0"
/>
<ListBox
x:Name="PART_ItemList" Grid.Row="0"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
ItemsSource="{Binding Suggestions, RelativeSource={RelativeSource TemplatedParent}}"
BorderThickness="0"
ItemTemplate="{TemplateBinding ItemTemplate}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Template="{DynamicResource {x:Static reskeys:ResourceKeys.PopListBoxControlTemplate}}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True"
DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
SelectedValuePath="{TemplateBinding ValuePath}"
KeyboardNavigation.AcceptsReturn="True"
KeyboardNavigation.DirectionalNavigation="Cycle"
BorderBrush="{TemplateBinding BorderBrush}"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
ScrollViewer.IsDeferredScrollingEnabled="True"
/>
<!-- RezizeGrip Thumb to support resizing the suggestion lib -->
<Thumb x:Name="PART_ResizeGripThumb"
Grid.Row="0"
Style="{DynamicResource {x:Static reskeys:ResourceKeys.ResizeGripStyleKey}}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="0"
Background="Transparent"
Width="16"
Height="16" />
</Grid>
</Border>
</Popup>
ほとんどのWPFのUIElement
コントロールは、彼らが最も広い要素できるだけ多くのスペースを占有しますので、「Width
」に設定することができAuto
性質を持っています。