开发者

Resizing GridView columns after making it visible

The setup:

ListView with GridView that is initially hidden when the window is loaded, and then made visible upon a certain user action.

The aim:

Be able to set relative width of GridView's columns.

The problem:

What I need can be achieved either by using a converter on the width (something similar to the answer here), or by adding a Behavior on the ListView (see this solution). The both approaches seem to be valid - but only for the controls that are rendered from the early beginning. In my case, the ActualWidth is always 0 when the calculations are made, and these calculations are not repeated when the ListView is made visible.

So, I guess, the real question here is how to get the columns' Width to be re-evaluated when ListView's ActualWidth gets greater than 0.

The solution would preferably be at the XAML level, without involving the code-behind - but that will do too, if that's the only alternative ;-)

Any suggestions?

P.S. Following Chris's question below, here's a clarification on how the ListView is hidden/shown: it's a child of another container control, hosted in a Grid column, and the width of that column is manipulated by a trigger.

<ColumnDefinition>
    <ColumnDefinition.Style>
        <Style>
            <Setter Property="ColumnDefinition.Width" Value="4*"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=OpenItems.Count}" Value="0">
                    <Setter Property="ColumnDefinition.Width" Value="0"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ColumnDefinition.Style>
</ColumnDefinition>

I tried to apply a similar trigger to the ListView's container itself (to manipulate its Visibility between Collapsed and Visible) instead, but the problem with that is that the Column doesn't shrink fro开发者_如何学编程m its original 4* width, so I see the (empty) control when it's supposed to be hidden.


How are you hiding/showing the ListView? The question seems to imply that you are doing so by setting the Width property to 0 (or non-zero to show it). Instead, you should try using the Visibility property (set to "Collapsed" to hide, or "Visible" to show). This should cause the column's width to be re-evaluated.

UPDATE:

Based on your updated question, I'd suggest checking out this solution: http://www.codeproject.com/KB/grid/ListView_layout_manager.aspx

I got it from here FWIW: WPF : Extend last column of ListView's GridView

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜