首页 新闻 会员 周边

WPF,Frame日志命令绑定失败的原因?

0
悬赏园豆:30 [待解决问题]

我使用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函数中能看到目标控件,也就是说命令的目标是应该找到了的,
但为什么还会绑定失败

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

ggtc的主页 ggtc | 初学一级 | 园豆:174
提问于:2024-04-14 20:45
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册