AgainMe AgainMe - 3 months ago 11
C# Question

ViewBox font not legible to minimum resolution

I'm using the

ViewBox
for display a list of labels in horizontal orientation and keep the legibilitym, the problem's that when I reduce the window to a minimum resolution that I set to:
800
I get this result:

enter image description here

how you can see the I can't read the contents. This situation only happen when the window is to minimum resolution, when is on max resolution the
ViewBox
working pretty good:

enter image description here

I don't know if I did something wrong. I never used the
ViewBox
, this is my code:

<Viewbox TextOptions.TextFormattingMode="Display" Stretch="Uniform" Grid.Row="1" Grid.Column="1" Grid.RowSpan="1">
<StackPanel>
<Grid Margin="0, 1, 0, 0">
<Label Content="Foo" FontWeight="Bold"/>
<Label Content="{Binding Path = EventLeague}" HorizontalAlignment="Center"/>
</Grid>
<Grid Margin="0,-10, 0, 0">
<Label Content="Date" FontWeight="Bold"/>
<Label Content="{Binding Path = EventDate}" HorizontalAlignment="Center"/>
</Grid>
<Grid Margin="0,-10, 0, 0">
<Label Content="Week" FontWeight="Bold"/>
<Label Content="{Binding Path = EventGameWeek}" HorizontalAlignment="Center"/>
</Grid>
<Grid Margin="0,-10, 0, 0">
<Label Content="Home" FontWeight="Bold"/>
<Label Content="{Binding Path = EventStart}" HorizontalAlignment="Center"/>
</Grid>
<Grid Margin="0,-10, 0, 0">
<Label Content="Away" FontWeight="Bold"/>
<Label Content="{Binding Path = EventStadium}" HorizontalAlignment="Center"/>
</Grid>
</StackPanel>
</Viewbox>

Answer

your Grids have no rows or column this means that everything goes into grid cell 0,0 on top of each other

try this

<Viewbox TextOptions.TextFormattingMode="Display" Stretch="Uniform" Grid.Row="1" Grid.Column="1" Grid.RowSpan="1" MinHeight="500"  MinWidth="500" >
    <StackPanel>
        <UniformGrid Columns="2">
            <Label Content="Foo" FontWeight="Bold"/>
            <Label Content="{Binding Path = EventLeague}" HorizontalAlignment="Center"/>
            <Label Content="Date" FontWeight="Bold"/>
            <Label Content="{Binding Path = EventDate}" HorizontalAlignment="Center"/>
            <Label Content="Week" FontWeight="Bold"/>
            <Label Content="{Binding Path = EventGameWeek}" HorizontalAlignment="Center"/>
            <Label Content="Home" FontWeight="Bold"/>
            <Label Content="{Binding Path = EventStart}" HorizontalAlignment="Center"/>
            <Label Content="Away" FontWeight="Bold"/>
            <Label Content="{Binding Path = EventStadium}" HorizontalAlignment="Center"/>
         </UniformGrid >
     </StackPanel>  
  </Viewbox>

Edit:

as you have clarified that the size is your problem not the unreadability of the controls

then the way a viewbox works is that is performs an image stretch on what ever is inside it to make it fit inside it,

so if the ViewBox is 100 wide but the items inside are 500 width then they are shrunk to 1/5 of their original size so as to fit

as you have Stretch="Uniform" then it will maintain the aspect ratio while shrinking and growing, if the size of the control is too small then set the MinHeight and MinWidth values of the Viewbox to control the minimum size

Comments