gpt4 book ai didi

c# - 与 DisplayMemberPath 的数据绑定(bind)在 menuitem 中转义下划线

转载 作者:行者123 更新时间:2023-12-03 10:22:28 28 4
gpt4 key购买 nike

好的,所以我们有一个最近的文件菜单选项。我们使用 MVVM 对 MenuItem 条目进行数据绑定(bind)并提供 DisplayMemberPath。但是 WPF 会转义字符串,因此下划线显示为下划线而不是访问键

enter image description here

<MenuItem x:Name="RecentScripts" DisplayMemberPath="Caption" Header="Recent _Files" cal:Message.Attach="OpenRecentScript($orignalsourcecontext)">
<MenuItem.Icon>
<Image Source="{StaticResource IconOpen}"/>
</MenuItem.Icon>
</MenuItem>

https://github.com/AndersMalmgren/FreePIE/blob/recet_files_shortcut/FreePIE.GUI/Views/Main/Menu/MainMenuView.xaml#L35

我们也有自定义主题,但禁用 MennuItem 的样式并没有帮助
https://github.com/AndersMalmgren/FreePIE/blob/recet_files_shortcut/FreePIE.GUI/Themes/ExpressionDark.xaml#L1921

最佳答案

将 DisplayMemberPath 替换为 ItemTemplate。如解释 here DisplayMemeberPath 是

a template for a single property, shown in a TextBlock



正如@XAMlMAX 提到的,TextBlock 不支持 AccessText,而 Label 支持。
            <MenuItem x:Name="RecentScripts" Header="Recent _Files" cal:Message.Attach="OpenRecentScript($orignalsourcecontext)">
<MenuItem.Icon>
<Image Source="{StaticResource IconOpen}"/>
</MenuItem.Icon>
<MenuItem.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Caption}"/>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>

关于c# - 与 DisplayMemberPath 的数据绑定(bind)在 menuitem 中转义下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47092423/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com