开发者

Elegant way of enabling specific Columns in a dynamic WPF UniformGrid to be resizable

开发者 https://www.devze.com 2023-01-26 12:51 出处:网络
like the title says: Is there an elegant way of enabling specific columns in a dynamic UniformGrid to be resizable?

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 UniformGri开发者_C百科d. 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


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 right Panel to go with.

Why don't you go with a StackPanel with Horizontal 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 use GridSplitter to make Grid columns resizable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号