扩展器标头删除"_"特点 [英] Expander Header removing "_" character

查看:39
本文介绍了扩展器标头删除"_"特点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVVM模式将XAML中的Expander.Header属性绑定到ViewModel中的字符串类型的后备公共属性:

I'm binding the Expander.Header property in XAML to a backing public property of string type in my ViewModel using the MVVM pattern:

public string EnumName {...}

我将此属性设置为"X_Y_Z",但是出于某些奇怪的原因,扩展器标题正在删除第一个下划线字符,并且将其显示为XY_Z.我尝试在前面添加"\"或将其设置为@"X_Y_Z",但没有运气.

I'm setting this property to "X_Y_Z" but for some strange reason the Expander Header is removing the first underscore character and it is displayed as XY_Z. I tried adding a "\" before or setting it to @"X_Y_Z" but no luck.

这是我的XAML绑定部分:

Here my XAML binding portion:

<Expander IsExpanded="true" Header="{Binding EnumName}">

有人知道我为什么会出现这种情况吗?它是以第一个"_"作为键盘快捷键还是元字符?

Anybody know why I'm getting this behavior? Is it taking the first "_" as a keyboard shortcut or a meta-character?

谢谢

推荐答案

@ HB.B.为我指明了正确的方向.我最终为扩展器设置了标题模板,如下所示,访问了祖先ListViewItem的DataContext:

@H.B. pointed me to the right direction. I ended up setting a Header Template for my Expander as follows, accessing the DataContext of the ancestor ListViewItem:

<Expander.HeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Path=DataContext.EnumName,RelativeSource={RelativeSource AncestorType=ListViewItem}}"/>
    </DataTemplate>
</Expander.HeaderTemplate>

由于我现在使用的是TextBlock,因此不会删除字符串中的任何"_"字符.

Since I'm now using a TextBlock it does not remove any of the "_" characters in my string.

这篇关于扩展器标头删除"_"特点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆