silverlight RowDetailsTemplate 是否存在不成文的限制?

发布于 2024-10-20 08:16:52 字数 2123 浏览 0 评论 0原文

我一直在盯着我的一个 Silverlight 数据网格中的 RowDetailsTemplate 定义的一些代码,并考虑重构它,因为它看起来像是有重复的网格。看完这个之后,我想我只需要一个数据网格,但事实证明,需要这个奇怪、神秘的双网格来让所有项目对齐:

<data:DataGrid.RowDetailsTemplate>
<DataTemplate>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition  />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>

        <Grid>
             <Grid.ColumnDefinitions>
                 <ColumnDefinition  />
                 <ColumnDefinition  />
                 <ColumnDefinition />
              </Grid.ColumnDefinitions>
              <Grid.RowDefinitions>
                  <RowDefinition MinHeight="20" />
                  <RowDefinition MinHeight="25" />
                  <RowDefinition MinHeight="25"  />
              </Grid.RowDefinitions>
              <TextBlock Grid.Row="0" Grid.Column="0" Text="Attendee Cap" Margin="0,0,50,0" />
              <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding AttendeeCap}"/>

              <TextBlock Text="Start Date" Grid.Row="1" Grid.Column="0" Margin="0,0,50,0" />
              <controls:DatePicker SelectedDate="{Binding StartDate, Mode=TwoWay}"  Grid.Row="1" Grid.Column="1"/>
             <input:TimePicker Value="{Binding StartDate, Mode=TwoWay}"   Grid.Row="1" Grid.Column="2" MinWidth="65" />

             <TextBlock Text="End Date" Grid.Row="2" Grid.Column="0" Margin="0,0,50,0" />
             <input:TimePicker Value="{Binding EndDate, Mode=TwoWay}"   Grid.Row="2" Grid.Column="2" MinWidth="65" />
            <controls:DatePicker SelectedDate="{Binding EndDate, Mode=TwoWay}"  Grid.Row="2" Grid.Column="1" />
        </Grid>
     </Grid>
</DataTemplate>

我想我可以去掉第一个网格定义,只保留内容之前的网格定义。问题是,如果我去掉那个网格,文本框、数据选择器和时间选择器就不会显示。

我是否遗漏了一些关于导致这种巫毒行为的 RowDetailsTemplate 的不成文规则?

I've been staring at some code for a RowDetailsTemplate definition in one of my Silverlight datagrids and thought about refactoring it because it looked like it had repeating grids. I thought, after looking at this, that I would only need one datagrid, but as it turns out, this wierd, mysterious double grid is required to get all the items to line up:

<data:DataGrid.RowDetailsTemplate>
<DataTemplate>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition  />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>

        <Grid>
             <Grid.ColumnDefinitions>
                 <ColumnDefinition  />
                 <ColumnDefinition  />
                 <ColumnDefinition />
              </Grid.ColumnDefinitions>
              <Grid.RowDefinitions>
                  <RowDefinition MinHeight="20" />
                  <RowDefinition MinHeight="25" />
                  <RowDefinition MinHeight="25"  />
              </Grid.RowDefinitions>
              <TextBlock Grid.Row="0" Grid.Column="0" Text="Attendee Cap" Margin="0,0,50,0" />
              <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding AttendeeCap}"/>

              <TextBlock Text="Start Date" Grid.Row="1" Grid.Column="0" Margin="0,0,50,0" />
              <controls:DatePicker SelectedDate="{Binding StartDate, Mode=TwoWay}"  Grid.Row="1" Grid.Column="1"/>
             <input:TimePicker Value="{Binding StartDate, Mode=TwoWay}"   Grid.Row="1" Grid.Column="2" MinWidth="65" />

             <TextBlock Text="End Date" Grid.Row="2" Grid.Column="0" Margin="0,0,50,0" />
             <input:TimePicker Value="{Binding EndDate, Mode=TwoWay}"   Grid.Row="2" Grid.Column="2" MinWidth="65" />
            <controls:DatePicker SelectedDate="{Binding EndDate, Mode=TwoWay}"  Grid.Row="2" Grid.Column="1" />
        </Grid>
     </Grid>
</DataTemplate>

I thought I could get rid of the first grid definition and just keep the one that is right before the content. The problem is, if I get rid of that grid, the textbox, data picker, and timepicker don't show up.

Am I missing some unwritten rule about the RowDetailsTemplate that is causing this voodoo behaviour?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-10-27 08:16:52

您可以删除第一个网格中的第三个 ColumnDefinition 条目,因为没有为其分配任何内容,列定义二和三时的唯一目的是将可用宽度分为三部分。如果执行此操作,您可能希望对第一列定义应用宽度,并将第二列保留为自动调整大小以填充剩余空间。

当网格内有项目时,它们会自动放置在第 0 列、第 0 行中,除非您另外指定。这意味着您的内部网格被放置在外部网格的第一列(第 0 列)中,因为它没有 Grid.Column="" 条目。此列当前使用其父容器的可用宽度的 1/3。 IOW,外部网格用于约束内部网格。

您可以尝试使用 Snoop 来确定当前和修改后的布局发生了什么,或者您可以添加边框网格,以便您可以在渲染后看到它们的确切位置。

You can possibly get rid of the third ColumnDefinition entry in the first grid as there is nothing assigned to it, the only purpose at the moment of column definitions two and three will be to divide the available width into three portions. If you do this though you may want to apply a width to the first column definition and leave the second column as auto sizing to fill the remaining space.

When you have items inside a grid, they are automatically placed in column 0, row 0, unless you specify otherwise. This means your inner grid is being placed in the first column (column 0) of the outer grid because it doesn't have a Grid.Column="" entry. This column is currently using 1/3 of the available width of its parent container. IOW, the outer grid is being used to constrain the inner grid.

You could try using Snoop to determine what is going on with your current and modified layouts, or you could add borders to the grids so you can see their exact positions once rendered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文