【问题标题】:WPF DataGrid Element Name of other DataGridTemplateColumn其他 DataGridTemplateColumn 的 WPF DataGrid 元素名称
【发布时间】:2012-10-25 12:48:46
【问题描述】:

我有两个 Datagrid 模板列。 1)拳头列是一个组合框 2) 第二列带有扩展的 IntergerUpDown 控件

我需要根据 Combox 框 SelectedItem 值设置 IntegerUpDown 最大值。

请帮助我如何做到这一点。下面是示例 xaml。

<Grid><DataGrid ItemsSource="{Binding List1}" Name="x1">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="ColorTemplate">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox  ItemsSource="{Binding DataContext.List2, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" 
                                      DisplayMemberPath="Name"  SelectedValue="{Binding ColourId}" SelectedValuePath="Id" Tag="{Binding Id}"
                                       HorizontalAlignment="Stretch" x:Name="discussTemplate" VerticalAlignment="Stretch"
                                         />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="UPDown" Width="Auto">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <extToolkit:IntegerUpDown AllowSpin="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Minimum="0"
                                                  x:Name="updown"
                                                  Maximum="{Binding ???}" >

                            </extToolkit:IntegerUpDown>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>

【问题讨论】:

    标签: wpf wpfdatagrid


    【解决方案1】:

    只是绑定到你的 itemsrow 的值?因此,如果 ColourID 是由组合框设置的 itemsrow 的属性。您可以将您的最大值绑定到 ColourID

    <extToolkit:IntegerUpDown AllowSpin="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Minimum="0"
                              Maximum="{Binding ColourId}" >
    </extToolkit:IntegerUpDown>
    

    【讨论】:

    • +1,别忘了在你的项目类中实现INotifyPropertyChanged(其中声明了ColourId属性)。
    • CombBox 的“TAG”属性中有一个值,该值必须设置为 IntergerUpDown 控件的最大值。
    猜你喜欢
    • 2014-06-12
    • 2013-06-30
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多