Menuitem剪切部分文字

时间:2014-11-06 18:42:05

标签: c# wpf xaml menuitem

MenuItem标题中的文本正在获取隐藏部分,如下图所示。全文是“InformaçõesdePagamento”,但其余部分是隐藏的。我需要这个组件的大小,宽度= 240

enter image description here

我的axml文件:

<Image.ContextMenu>

    <ContextMenu HorizontalAlignment="Left" Width="240">
        <MenuItem x:Name="infoPagamento" Header="_Informações de Pagamento" Cursor="Hand" ToolTip="Online" Click="statusOn_Click" Background="White" Margin="5" >
            <MenuItem.Icon>
                <Image Source="../Imagens/icons/menuusuario/icon_financeiro.png" />
            </MenuItem.Icon>
        </MenuItem>

        <MenuItem x:Name="alteracaoPlano" Header="Alteração de plano" Cursor="Hand" ToolTip="Alteração de plano" Click="statusAusente_Click" Background="White" Margin="5">
            <MenuItem.Icon>
                <Image Source="../Imagens/icons/menuusuario/icon_tarefa.png" />
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem x:Name="Relatorios" Header="Relatórios" Cursor="Hand" ToolTip="Ocupado" Click="statusOcupado_Click" Background="White" Margin="5">
            <MenuItem.Icon>
                <Image Source="../Imagens/icons/menuusuario/icon_relatorios.png" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </MenuItem.Icon>
        </MenuItem>

        <MenuItem x:Name="Ajuda" Header="Ajuda" Cursor="Hand" ToolTip="Offline" Click="statusOff_Click" Background="White" Margin="5">
            <MenuItem.Icon>
                <Grid>
                    <Ellipse Width="20" Height="20" Fill="#48026E" />

                    <Label Content="?" Padding="0" 
                            VerticalAlignment="Center" HorizontalAlignment="Center" 
                            Foreground="White" FontSize="14" Cursor="Hand"/>
                </Grid>
            </MenuItem.Icon>
        </MenuItem>

    </ContextMenu>
</Image.ContextMenu>

我的资源:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Style TargetType="{x:Type ContextMenu}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ContextMenu}">

                <Border x:Name="Border"
                        Background="White"
                        BorderThickness="1" BorderBrush="Transparent" 
                        Margin="3" CornerRadius="10">
                    <StackPanel IsItemsHost="True"/>
                </Border>

            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

2 个答案:

答案 0 :(得分:1)

我在下拉菜单中遇到类似的问题。问题出在诸如CTRL + D(输入手势文本)之类的快捷方式的保留空间中。为了克服限制,我不得不将菜单项的宽度设置为固定大小,用文本块覆盖menuitem标头,将其宽度设置为自动(固定宽度不能像预期的那样工作),并为文本块设置负边距(其大小可能因您的问题而不同) )。

一些简短的例子:

<Menu IsMainMenu="True" Height="auto" Width="220" Margin="0" VerticalAlignment="Center" VerticalContentAlignment="Stretch" HorizontalAlignment="Center" HorizontalContentAlignment="Stretch">

<MenuItem BorderThickness="0" Width="220"  Margin="0" VerticalAlignment="Center" VerticalContentAlignment="Stretch" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch">
    <MenuItem.Icon>
        <Ellipse Width="25" Height="25" HorizontalAlignment="Center" Stretch="Uniform">
            <Ellipse.Fill>
                <ImageBrush x:Name="imgAvatar" ImageSource="..." TileMode="Tile" Stretch="UniformToFill" />
            </Ellipse.Fill>
        </Ellipse>
    </MenuItem.Icon>
    <MenuItem.Header>
        <TextBlock Text="Some long long text" Width="auto" TextWrapping="Wrap"  Margin="0,0,-75,0" VerticalAlignment="Center" TextAlignment="Left" HorizontalAlignment="Left"/>
    </MenuItem.Header>

    <MenuItem BorderThickness="0" Width="220"  Margin="0" VerticalAlignment="Center" VerticalContentAlignment="Stretch" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch">
        <MenuItem.Icon>
            <Ellipse Width="25" Height="25" HorizontalAlignment="Center" Stretch="Uniform">
                <Ellipse.Fill>
                    <ImageBrush x:Name="imgAvatar" ImageSource="..." TileMode="Tile" Stretch="UniformToFill" />
                </Ellipse.Fill>
            </Ellipse>
        </MenuItem.Icon>
        <MenuItem.Header>
            <TextBlock Text="Some long long text 2" Width="auto" TextWrapping="Wrap"  Margin="0,0,-75,0" VerticalAlignment="Center" TextAlignment="Left" HorizontalAlignment="Left"/>
        </MenuItem.Header>
    </MenuItem>
</MenuItem>

</Menu>

答案 1 :(得分:0)

尝试将MenuItem的宽度设置为“自动”