将DataTemplate网格属性内部绑定到其列定义

时间:2017-03-16 09:59:36

标签: c# .net wpf

我需要的是保证我的所有专栏在它们更大时都不会被其内容控件拉长。现在确实如此。我在这里找到了一个解决方案enter link description here。它有效,但我想知道是否可以以某种方式绑定到项目模板网格宽度本身而不是绑定到ListBox宽度?如果可能的话,这是在性能方面采取的正确方法吗?

<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>

1 个答案:

答案 0 :(得分:1)

您可以将父<Grid x:Name="ParentGrid"> <Grid.ColumnDefinitions> <ColumnDefinition Width="{Binding Path=ActualWidth, ElementName=ParentGrid, Converter={StaticResource YourConverter}"/> <!-- ... --> </Grid.ColumnDefinitions> <!-- ... --> </Grid> 命名并绑定到它,如:

Grid

另一种方法是将<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Grid}}, Converter={StaticResource YourConverter}"/> <!-- ... --> </Grid.ColumnDefinitions> <!-- ... --> </Grid> 绑定为父级,如:

var html = "<tr><td>" + user_id + "</td> <td>" + name + "</td> <td>" + email +
"</td><td>" + address + "</td><td>" + dabba_type + "</td><td>" + session + "  </td><td>" + start +
"</td><td>" + end + "</td><td>" + phone + "</td><td>" + "Rs " + price + "</td><td>" + feedback + "</td></tr>";

$("#table_body").html(html);
相关问题