Ignacio Soler Garcia
Ignacio Soler Garcia

Reputation: 21855

How to Bind two DataGridColumns Widths in WPF?

I'm aware of DataGridColumns not being on the logical nor visual tree of a grid. I'm using the proxy as shown here.

I need to bind the width of some of the columns. I usually use bindings like this one:

Width="{Binding ActualWidth, ElementName=LastOperationColumn}

However, it is not working. Any idea on how to do this?

Upvotes: 2

Views: 1474

Answers (3)

brunnerh
brunnerh

Reputation: 184506

You cannot use ElementName in a DataGrid column because they are not objects in the visual or logical tree, they have no namescope which is needed for those bindings. You can however use Source and x:Reference:

{Binding ActualWidth, Source={x:Reference LastOperationColumn}}

Of course this won't change that the binding is destroyed if this column is resized manually.

Upvotes: 2

Tod
Tod

Reputation: 8242

I just looked at some code where I'm setting MaxWidth and I think it should be the same. Here's the syntax I used.

<DataGridTextColumn...     
    MaxWidth="{Binding Source={x:Static Properties:Settings.Default}, 
                                            Mode=OneWay, 
                                            Path=DescriptionMaxWidth}">

Upvotes: 1

Prathibha
Prathibha

Reputation: 166

Try this: Width="{Binding Path=ActualWidth,ElementName=LastOperationColumn}"

Upvotes: 0

Related Questions