我在使用TabControl对象开发WPF应用程序时遇到了问题.我试图调试并找到问题,最后我得到了它,但我没有找到任何解决方法.这是一些解释:
我使用了这个数据网格过滤库(这里是一个codeproject url),这是最好的(从我的观点来看).我想使用谷歌材料设计主题自定义它并更改一些图形功能,例如使用数据网格的第一个标签页中的切换按钮来隐藏/显示过滤选项.
我创建了一个用户控件并将自定义数据网格放入其中.然后我将该控件嵌入到tabItem中.当我将此控件设置为第一个tabItem时,一切正常.但是当我将用户控件更改为另一个tabItem时,切换按钮不起作用.
这是我的主窗口xaml代码不起作用:
<TabControl x:Name="tabControl">
<TabItem Header="1'st Tab">
<ContentControl DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
<Button Content="Do no thing"></Button>
</ContentControl>
</TabItem>
<TabItem Header="2'nd Tab">
<ContentControl DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
<local:UserControl1/>
</ContentControl>
</TabItem>
</TabControl>
Run Code Online (Sandbox Code Playgroud)
请注意,如果我更改TabItems的顺序,它可以正常工作.有没有人有如何解决这个问题的建议?这是我在Github上的示例项目代码
编辑:今天,我用"WPF Inspector"测试我的应用程序,找到视觉和逻辑树的结构.这种行为太奇怪了,因为当我将"WPF Inspector"附加到我的应用程序时,一切都开始起作用了.以下GIF就是我做的: