1

I have a windows application using a custom ComboBox. In my machine text appears properly. But in other machines it is cutting off a little bit. Any suggestions please?

<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>
Daniele Sartori
  • 1,674
  • 22
  • 38
newbee
  • 33
  • 5
  • 1
    Height=“5”? Try making it big enough. Different machines will have different font settings and different versions of Windows will have different default control templates. Allow for normal variation. If the user indulges in ridiculous variation, that’s not your problem. – 15ee8f99-57ff-4f92-890c-b56153 Nov 27 '17 at 22:37

1 Answers1

1

I strongly suggest to everyone, to not hard code Height and Width in your controls. It's a much better practice to learn to use the wide choice of container that WPF offers. In particular, the Grid is the most basic, but also in my opinion the most powerful. This because you can define rows and columns with proportional and Auto size. This will allow you to get rid of any concern regarding the resolution of the destination monitor, by creating resizable application.

In your case, as it was mentioned in the comment, your height is probably too small. So you can define a grid and place your combobox inside it

    <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>
Daniele Sartori
  • 1,674
  • 22
  • 38