WPF,Frame控件的一个BUG

我使用WPF默认的frame

<Frame Style="{DynamicResource FrameStyle1}" x:Name="frame" Height="80" NavigationUIVisibility="Visible"/>

然后添加几次导航

Task.Run(async () =>
{
this.Dispatcher.BeginInvoke(() => this.frame.Navigate(new Page1() as Page, "page1"));
await Task.Delay(1000);
this.Dispatcher.BeginInvoke(() => this.frame.Navigate(new Page2() as Page, "page2"));
await Task.Delay(1000);
this.Dispatcher.BeginInvoke(() => this.frame.Navigate(new Page3() as Page, "page3"));
});

问题是一打开导航日志

就会出现绑定失败
找不到源: RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Menu', AncestorLevel='1'。
这是导航日志命令MenuItem.CommandTarget的目标没找到。
就是这里

<Setter Property="Command" Value="NavigationCommands.NavigateJournal"/>
<Setter Property="CommandTarget" Value="{Binding Path=TemplatedParent, RelativeSource={RelativeSource AncestorType={x:Type Menu}},Converter={StaticResource ResourceKey=debugbinding}}"/>
<Setter Property="CommandParameter" Value="{Binding RelativeSource={RelativeSource Mode=Self}}"/>

经过我长时间排查,使用debugbinding转换器介入绑定过程,发现转换器的Convert函数中能看到目标控件,也就是说命令的目标是应该找到了的,
但为什么还会绑定失败

应用样式还是我为了方便排查,原来是不使用样式也会出现绑定错误

posted @   ggtc  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
//右下角目录
点击右上角即可分享
微信分享提示