views:

1359

answers:

2

Hi, i am building a context menu for a WPF c# application and just for simplicity's sake, if i have text and then i add an image, the text is always aligned at the top of the menu items cell and i cant figure out how to align it to the center. i have tried the veticalalignment property and veticalcontentalignment property but they dont help.. any ideas?

A: 

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>
Oskar
A: 

Whenever I get stuck like this, I fire up Snoop (http://blois.us/snoop) - make sure your app is set to compile as 32-bit (it's not by default!), then use Snoop to figure out which control is aligned incorrectly

Paul Betts