我怎样才能类型的子控件ComboBox中MyContainer Grid的WPF?
<Grid x:Name="MyContainer">
<Label Content="Name" Name="label1" />
<Label Content="State" Name="label2" />
<ComboBox Height="23" HorizontalAlignment="Left" Name="comboBox1"/>
<ComboBox Height="23" HorizontalAlignment="Left" Name="comboBox3" />
<ComboBox Height="23" HorizontalAlignment="Left" Name="comboBox4" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
这行给了我一个错误:
var myCombobox = this.MyContainer.Children.GetType(ComboBox);
Run Code Online (Sandbox Code Playgroud) 嗨,我在itemscontrol的datatemplate中只有一个文本框.当我将itemcontrols绑定到一个可观察的集合时,我得到两个文本框.但我需要根据每个文本框进行一些操作,我希望使用一些id分别找到每个文本框.
任何人都可以帮助如何在WPF中的itemscontrol中找到控件.
我有一个包含许多项的DataGrid,我需要以编程方式滚动到SelectedItem.我在StackOverflow和Google上搜索过,似乎解决方案是ScrollIntoView,如下所示:
grid.ScrollIntoView(grid.SelectedItem)
Run Code Online (Sandbox Code Playgroud)
向上或向下滚动DataGrid,直到所选项目处于焦点.但是,根据相对于所选项目的当前滚动位置,所选项目可能最终成为DataGrid的ScrollViewer中的最后一个可见项目.我希望所选项目将成为ScrollViewer中的第一个可见项目(假设DataGrid中有足够的行允许这样做).所以我尝试了这个:
'FindVisualChild is a custom extension method that searches in the visual tree and returns
'the first element of the specified type
Dim sv = grid.FindVisualChild(Of ScrollViewer)
If sv IsNot Nothing Then sv.ScrollToEnd()
grid.ScrollIntoView(grid.SelectedItem)
Run Code Online (Sandbox Code Playgroud)
首先,我滚动到DataGrid的末尾,然后才滚动到SelectedItem,此时SelectedItem显示在DataGrid的顶部.
我的问题是滚动到DataGrid的末尾运行良好,但随后滚动到所选项目并不总是有效.
如何解决此问题,或者是否有其他替代策略可以滚动到顶部位置的特定记录?
wpf ×3
c# ×1
datagrid ×1
findcontrol ×1
itemscontrol ×1
scrollviewer ×1
vb.net ×1
wpf-controls ×1