WPF组合框在不同的机器中显示不同

WPF组合框在不同的机器中显示不同,wpf,combobox,Wpf,Combobox,我有一个使用自定义组合框的windows应用程序。在我的机器中,文本正确显示。但在其他机器中,它会稍微被切断。有什么建议吗 <ComboBox Width="140" Height="5" ItemsSource="{Binding SecurityContexts, Mode=OneWay}" SelectedItem="{Binding ActiveSecurityContext, Mode=TwoWay}

我有一个使用自定义组合框的windows应用程序。在我的机器中,文本正确显示。但在其他机器中,它会稍微被切断。有什么建议吗

<ComboBox Width="140" Height="5"
                    ItemsSource="{Binding SecurityContexts, Mode=OneWay}"
                    SelectedItem="{Binding ActiveSecurityContext, Mode=TwoWay}"
                    ToolTip="Working Location">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <!--<TextBlock Text="{Binding Location}"/>-->
            <TextBlock Height="27">
               <TextBlock.Text>
                  <MultiBinding StringFormat="{}{0}&#x0a;{1}">
                     <Binding Path="AddBlank" FallbackValue=''/> <!--Just to add a blank field to hide the location details-->
                     <Binding Path="Location" />
                  </MultiBinding>
               </TextBlock.Text>
            </TextBlock>
       </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

我强烈建议大家,不要在控件中硬编码高度和宽度。学习使用WPF提供的多种容器是更好的做法。特别是,
网格
是最基本的,但在我看来也是最强大的。这是因为您可以使用和大小定义行和列。这将允许您通过创建可调整大小的应用程序,消除与目标监视器的分辨率有关的任何问题

就你而言,正如评论中提到的,你的身高可能太小了。因此,您可以定义一个网格并将您的组合框放在其中

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"/>
            <ColumnDefinition Width="5*"/>
        </Grid.ColumnDefinitions>
        <ComboBox Grid.Row="0" Grid.Column="0"
                ItemsSource="{Binding SecurityContexts, Mode=OneWay}"
                SelectedItem="{Binding ActiveSecurityContext, Mode=TwoWay}"
                ToolTip="Working Location">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <!--<TextBlock Text="{Binding Location}"/>-->
                    <TextBlock Height="27">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0}&#x0a;{1}">
                                <Binding Path="AddBlank" FallbackValue=''/>
                                <!--Just to add a blank field to hide the location details-->
                                <Binding Path="Location" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </Grid>


Height=“5”?试着让它足够大。不同的计算机将具有不同的字体设置,不同版本的Windows将具有不同的默认控件模板。考虑正常变化。如果用户沉迷于荒谬的变化,那不是你的问题。非常感谢Daniele