我在 Telerik RadGridView 中有一个 RadComboBox 列,我想要做的是当您更改 RadComboBox 中的项目时,禁用< strong> GridViewRow RadComboBox ;为此,我需要获得 RadComboBox 的父级,但我尝试的不起作用
这是我的 RadGridView 代码:
<telerik:RadGridView x:Name="dtgResumen" VerticalAlignment="Stretch" VerticalContentAlignment="Center" AutoGenerateColumns="False" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" FontSize="14" RowIndicatorVisibility="Collapsed" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" IsFilteringAllowed="False" GridLinesVisibility="Both" >
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn x:Name="colStatus" Header="STATUS" Width="1.3*" >
<telerik:GridViewDataColumn.HeaderCellStyle>
<Style TargetType="telerik:GridViewHeaderCell">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="#538DD5" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="FontSize" Value="12" />
</Style>
</telerik:GridViewDataColumn.HeaderCellStyle>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<telerik:RadComboBox Name="comboBoxStatus" SelectedIndex="0" SelectionChanged="comboBox_SelectionChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<telerik:RadComboBox.Items>
<telerik:RadComboBoxItem Content="Activa" Foreground="Green" />
<telerik:RadComboBoxItem Content="Cancelada" Foreground="Red" />
</telerik:RadComboBox.Items>
</telerik:RadComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
这是事件中的代码:
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var combo = sender as RadComboBox;
var row = FindParent<GridViewRow>(combo);
}
这是FindParent代码:
public static Parent FindParent<Parent>(DependencyObject child) where Parent : DependencyObject
{
DependencyObject parentObject = child;
//We are not dealing with Visual, so either we need to fnd parent or
//get Visual to get parent from Parent Heirarchy.
while (!((parentObject is System.Windows.Media.Visual) || (parentObject is System.Windows.Media.Media3D.Visual3D)))
{
if (parentObject is Parent || parentObject == null)
return parentObject as Parent;
else
parentObject = (parentObject as FrameworkContentElement).Parent;
}
//We have not found parent yet , and we have now visual to work with.
parentObject = VisualTreeHelper.GetParent(parentObject);
//check if the parent matches the type we're looking for
if (parentObject is Parent || parentObject == null)
return parentObject as Parent;
else
//use recursion to proceed with next level
return FindParent<Parent>(parentObject);
}
我也试过这个,但它不起作用:
var combo = sender as RadComboBox;
var row = combo.ParentOfType<GridViewRow>();