Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: GridViewColumn resize event

I'm using ListView with GridView. Is there GridViewColumn resize event?

like image 311
Marat Faskhiev Avatar asked Feb 05 '10 04:02

Marat Faskhiev


2 Answers

Although GridViewColumn does not appear to have a Resize event, you can bind to the ColumnWidth property.

You can verify this with sample XAML below - no code behind needed for this example. It binds only in one direction, from the column width to the text box, and when you resize you will see the textbox immediately update with the column width.

(This is just a simple example; if you want to pick up the resize in code I would create a class with a Width property so binding will work in both directions).

<StackPanel>
    <ListView>
        <ListView.View>
            <GridView>
                <GridViewColumn Width="{Binding ElementName=tbWidth1, Path=Text, Mode=OneWayToSource}"  />
                <GridViewColumn Width="{Binding ElementName=tbWidth2, Path=Text, Mode=OneWayToSource}"  />
            </GridView>
        </ListView.View>
        <ListViewItem>Item 1</ListViewItem>
        <ListViewItem>Item 2</ListViewItem>
    </ListView>
    <TextBox Name="tbWidth1" />
    <TextBox Name="tbWidth2" />
</StackPanel>
like image 110
Edward Avatar answered Sep 25 '22 09:09

Edward


I will handle the PropertyChanged event instead. The PropertyChanged event is not seen in the Visual Studio intellisense, but you can trick it :)

 GridViewColumn column = ...
 ((System.ComponentModel.INotifyPropertyChanged)column).PropertyChanged += (sender, e) =>
 {
     if (e.PropertyName == "ActualWidth")
     {
         //do something here...
     }
 };
like image 30
chenz Avatar answered Sep 26 '22 09:09

chenz