Reputation:
I am building a context menu for a WPF application and if I have text and then I add an image, the text is always aligned at the top of the menu item and I can't figure out how to align it to the center.
I have tried the VerticalAlignment
and VerticalContentAlignment
properties but they dont help.. any ideas?
Upvotes: 1
Views: 4214
Reputation: 74692
Whenever I get stuck like this, I fire up Snoop (https://github.com/snoopwpf/snoopwpf) and use it to figure out which control is aligned incorrectly.
Upvotes: 1
Reputation: 8175
I guess it depends on what kind of panel you are using to host the text and the image. I tried with a StackPanel
and once I added VerticalAlignment="Center"
, the text was aligned correctly. Please provide some more information if it still doesn't work out for you.
<Button Content="Right-click me">
<Button.ContextMenu>
<ContextMenu>
<MenuItem>
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center">Menu item 1</TextBlock>
<Image Source="image.png" Height="50" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
</ContextMenu>
</Button.ContextMenu>
</Button>
Upvotes: 1