Omer Raviv
Omer Raviv

Reputation: 11827

WPF ContextMenu that supports Rich Text?

Is there any code or 3rd party control out there that will allow me to show a ContextMenu in WPF, where the Header text is richly formatted (ie, contains different colors, font sizes, etc).

Upvotes: 0

Views: 251

Answers (2)

Rafal
Rafal

Reputation: 1091

You can customize MenuItem as you want:

    <ListBox>
        <ListBoxItem Content="Item">
            <ListBoxItem.ContextMenu>
                <ContextMenu>
                    <MenuItem>
                        <MenuItem.Header>
                            <TextBlock FontFamily="Segoe UI"
                                       FontStyle="Italic"
                                       Foreground="Green"
                                       Text="Some header" />
                        </MenuItem.Header>
                    </MenuItem>
                </ContextMenu>
            </ListBoxItem.ContextMenu>
        </ListBoxItem>
    </ListBox>

Also you can create a style for TextBlock which is inside of MenuItem.Header.

Upvotes: 1

David
David

Reputation: 16277

WPF Popup control can serve such purposes:

<Popup Name="myPopup" IsOpen="True">
    <Label Name="myLabel" Content="Some Caption" 
          Background="Black" Foreground="White"/>
    <...other controls you like.../>
</Popup>

Upvotes: 0

Related Questions