0

What I need is to guaranty that all my columns aren't gonna be stretched by its content controls when they are bigger. Now it does. I found a solution here enter link description here. It works, but I'm wondering if it's possible to bind to item template Grid Width itself somehow instead of binding to the ListBox Width? And if it's possible is it proper way to go in terms of performance?

<telerik:RadListBox.ItemTemplate>
                <DataTemplate>
                    <Grid> <-- need to bind this Grid Width
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" /> <-- to these columns width for further calculations
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
Community
  • 1
  • 1
oschepkov
  • 75
  • 1
  • 8
  • I am quite sure you are misusing star units, more likely you need `Auto` there, nested grid or perhaps `MaxWidth/MinWidth`. Hard to tell as you don't show complete layout, but it should be possible to avoid requirement to set column width explicitly. – Sinatr Mar 16 '17 at 10:26

1 Answers1

1

You can name the parent Grid and bind to it like:

<Grid x:Name="ParentGrid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="{Binding Path=ActualWidth,
                                          ElementName=ParentGrid,
                                          Converter={StaticResource YourConverter}"/>
        <!-- ... -->
    </Grid.ColumnDefinitions>
    <!-- ... -->
</Grid>

An other way is to bind the Grid as parent like:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="{Binding Path=ActualWidth,
                                          RelativeSource={RelativeSource AncestorType={x:Type Grid}},
                                          Converter={StaticResource YourConverter}"/>
        <!-- ... -->
    </Grid.ColumnDefinitions>
    <!-- ... -->
</Grid>
Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49