سؤال

I have an expander:

 <Expander Header="{Binding Name}" IsExpanded="False" >

How do i add a ToolTip for it?

And another question, the Name of the header is long and for some reason the expander left one of the characters in the middle of the Name.

For example:

  • Name is - something_second
  • Display shows: somethingsecond

What could it be?

I thought about making it wrap the text but couldn't figure how to do so.

EDIT:

Ok so i managed to make a tooltip, i user a static resource. But still the text is cutted for some unreasonable reason

هل كانت مفيدة؟

المحلول

When there is an underscore in a label, WPF interprets it as an access key. One way to get around this is to use a double-underscore, which escapes the access character:

public string Name
{
    get { return _name; }
    set { _name = (value ?? "").Replace("_", "__");
}
private string _name;

Alternately: it is possible to turn off the access character for individual controls, using ContentPresenter.RecognizesAccessKey. Unfortunately, to make use of this, you typically have to copy/modify the default control template and set any ContentPresenters' "RecognizesAccessKey" property to false. For Expander, for example, you would have modify this part of the default template:

<ContentPresenter Grid.Column="1"
                  Margin="4"
                  ContentSource="Header"
                  RecognizesAccessKey="False" />

One more alternative (and actually probably the easiest). Use a TextBlock for the header -- that will prevent the access key from being used:

<Expander IsExpanded="False">
    <Expander.Header>
        <TextBlock Text="{Binding Name}" />
    </Expander.Header>
</Expander>

Related Questions

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top