使动态 WPF UniformGrid 中的特定列可调整大小的优雅方法
就像标题所说:是否有一种优雅的方法可以使动态 UniformGrid 中的特定列可调整大小?
详细信息:
我有一个 ItemsControl 并将 ItemsPanelTemplate 设置为 UniformGrid 类型。 ItemTemplate 设置为呈现列内容的自定义控件。
这是 xaml 摘录:
<ItemsControl x:Name="PART_Dimensions"
Grid.Column="1" HorizontalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding
Path=ItemsSource.Count,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ItemsControl}}}"
IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:Dimension
PropertyA="{Binding SourceA}"
ItemsSource="{Binding SourceB}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
现在,我想要实现的是使特定列的大小成为可能,为它们提供静态宽度,同时仍然允许其他列的宽度统一。
有人给我指点方向吗?我希望避免 UniformGrid 渲染的过于具体的自定义实现,是否有一种聪明而简单的方法来做到这一点?
提前致谢 关于 奥莱
like the title says: Is there an elegant way of enabling specific columns in a dynamic UniformGrid to be resizable?
The details:
I have a ItemsControl and set the ItemsPanelTemplate to be of type UniformGrid. The ItemTemplate is set to a Custom Control that renders the column content.
Here is the xaml excerpt:
<ItemsControl x:Name="PART_Dimensions"
Grid.Column="1" HorizontalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding
Path=ItemsSource.Count,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ItemsControl}}}"
IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:Dimension
PropertyA="{Binding SourceA}"
ItemsSource="{Binding SourceB}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
Now, what i'm trying to achieve is to make it possible, that specific columns are resizable, giving them a static width while still allowing the other columns to be sized uniformly in width.
Has anyone some direction to point me to? I was hoping to avoiding too specific custom implementations of the Rendering of the UniformGrid, is there a smart and easy way doing this?
thanks in advance
with regards
Ole
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您试图保留一些列具有静态宽度并让其他列具有动态宽度,我会说
UniformGrid
不是正确的Panel
。为什么不选择具有水平方向的 StackPanel 呢?从您的代码中,我发现您只需要一行。
如果这对您不起作用,请使用
Grid
。您将需要编写一些代码,但这会给您最好的结果。您可以使用GridSplitter
来调整Grid
列的大小。If you are trying to keep a few columns with static width and let others have a dynamic width, I would say
UniformGrid
is not the rightPanel
to go with.Why don't you go with a
StackPanel
withHorizontal Orientation
? From you code, I see you only need one row.If that does not work for you, go with
Grid
. You will need to write some code but that will give you the best results. You can useGridSplitter
to makeGrid
columns resizable.