0
我試圖在DataGrid中的DataTemplate中查找ComboBox。從指定的DataGridRow中查找DataGrid中的ComboBox
首先,我試試吧:
VisualTreeHelper.GetChildrenCount(dataGridRowInstance);
但它總是返回0
XAML:
<DataGrid HorizontalAlignment="Left" Margin="10,54,0,0" VerticalAlignment="Top" Height="231" Width="571" ItemsSource="{Binding}" AutoGenerateColumns="false" x:Name="gridRestore" CellStyle="{StaticResource CellVerticalAlignCenter}">
<DataGrid.Columns>
<DataGridTextColumn Header="Created Date" Binding="{Binding Path=CreationTime, ConverterCulture=pt-BR}" Width="120"/>
<DataGridTextColumn Header="Length" Binding="{Binding Path=Length}" Width="120"/>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" Width="200"/>
<DataGridTemplateColumn Width="*" Header="Restore To...">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="cbx" Width="120" DropDownOpened="Cbx_OnDropDownOpened" SelectionChanged="Cbx_OnSelectionChanged"></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
在恢復,我想根據測試結果隱藏組合框我在DataGrid.LoadingRow事件中做。
你可以發佈DataGrid.LoadingRow事件嗎? – Shoe
什麼是dataGridRowInstance?請發佈更多代碼。 –