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函数中能看到目标控件,也就是说命令的目标是应该找到了的,
但为什么还会绑定失败
应用样式还是我为了方便排查,原来是不使用样式也会出现绑定错误
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性