I have been given a custom font to use in our corporate application. The font itself looks fine in Word, but is rendered "elevated" by WPF. Consider the screen prints below:
When the Calibre font is rendered in WPF (I manually drew the red line):
When the Calibre font is rendered in Word:
XAML:
<StackPanel Orientation="Horizontal" Margin="10,10,0,100">
<TextBlock Text="Arial" FontFamily="Arial" FontSize="48" Padding="5,0" Margin="0" Background="AntiqueWhite" VerticalAlignment="Center" />
<TextBlock Text="Arial Bold" FontFamily="Arial Bold" FontSize="48" Padding="5,0" Margin="0" Background="AntiqueWhite" VerticalAlignment="Center" />
<TextBlock Text="Calibre Regular" FontFamily="Calibre Regular" FontSize="48" Padding="5,0" Margin="0" Background="AntiqueWhite" VerticalAlignment="Center" />
<TextBlock Text="Calibre Bold" FontFamily="Calibre Bold" FontSize="48" Padding="5,0" Margin="0" Background="AntiqueWhite" VerticalAlignment="Center" />
<TextBlock Text="Calibri Regular" FontFamily="Calibri" FontSize="48" Padding="5,0" Margin="0" Background="AntiqueWhite" VerticalAlignment="Center" />
<TextBlock Text="Calibri Bold" FontFamily="Calibri Bold" FontSize="48" Padding="5,0" Margin="0" Background="AntiqueWhite" VerticalAlignment="Center" />
</StackPanel>
Any idea? I am truly stumped on this one!
OK, I stumbled across a fix. I opened the font in a free font editor called Type Light to verify everything looked correct in the font. I saved the font as a new file and tried that file. It solved the issue. Clearly something was wrong with the OTF file.
http://www.cr8software.net/typelight.html
Related
I have problem with align two labels who has different size and are neighbors. I have to show variable as big size and units as small. But because of the different position of the font baseline, the texts are not located on the same line. Look at my xaml:
<StackPanel VerticalAlignment="Bottom" Orientation="Horizontal">
<Label Content="5" FontSize="70" FontWeight="DemiBold" Foreground="White" Padding="0" Margin="0" BorderBrush="White" BorderThickness="1" />
<Label Content="s" FontSize="14" Foreground="White" Padding="0" Margin="0" BorderBrush="White" BorderThickness="1" VerticalAlignment="Bottom" />
</StackPanel>
I see solution of this problem: I can pick up margin or padding, but it is not good decision. In addition, I can not remove the upper gap of a larger text. May be exist more elegant way to deside this problem. Please, show me this, if somebody know, or tell, that is isn't possible, and I will pick up margin or padding. I was looking for a solution for a long time. The most similar here: WPF: Aligning the base line of a Label and its TextBox
But my elements has different size and this way is bad for me.
Thanks for any help!
If you are not required to use Labels, you can achieve baseline alignment by using Runs inside a TextBlock.
<TextBlock VerticalAlignment="Bottom">
<Run Text="5" FontSize="70" FontWeight="DemiBold" Foreground="White" />
<Run Text="s" FontSize="14" Foreground="White" />
</TextBlock>
You should use that margins:
<StackPanel VerticalAlignment="Bottom" Orientation="Horizontal">
<Label Content="5" FontSize="70" FontWeight="DemiBold" Foreground="White" Padding="0" Margin="0" BorderBrush="White" BorderThickness="1" />
<Label Content="s" FontSize="14" Foreground="White" Padding="0" Margin="0 0 0 12" BorderBrush="White" BorderThickness="1" VerticalAlignment="Bottom" />
</StackPanel>
I'd like to have a button with text at the bottom, but more text in the background, specifically from a UI font. That way the content text at the bottom can be seen over the background.
It doesn't seem like StackPanels and DockPanels help as they always allocate room for each control so they don't overlap.
Something like:
<Button HorizontalContentAlignment="Stretch" VerticalContentAlignment="Bottom" FontFamily="Segoe UI Symbol">
<Button.Background>
<TextBox Text="" Foreground="White" Background="#FF5B9BD5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0"/>
</Button.Background>
<TextBox Text="Text" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" BorderThickness="0"/>
</Button>
This code does not work as the Background does not support controls, only Brushes.
Using a grid achieves this:
<Button VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Foreground="White" FontFamily="Segoe UI Symbol" FontStretch="Expanded" BorderThickness="0">
<Grid>
<TextBox Text="" Foreground="White" Background="#FF5B9BD5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="36" BorderThickness="0"/>
<TextBox Text="Text" Foreground="White" Background="#FF5B9BD5" HorizontalContentAlignment="Center" VerticalAlignment="Bottom" BorderThickness="0"/>
</Grid>
</Button>
I am currently sitting on a Silverlight-Listbox and have some
trouble getting my listBox right.
Its (visually) starts from the second item.
I have to scroll up to see the first one.
Why is this happening and how could I fix this?
<ListBox x:Name="ServingsList"
Foreground="White"
Background="#FFB88A8A"
SelectionChanged="servingSelected"
Margin="0,0,0,297">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="70" Width="432">
<Rectangle x:Name="Linie"
Fill="#FF8D8D8D"
HorizontalAlignment="Right"
Height="2"
StrokeThickness="0"
VerticalAlignment="Top"
Width="380"
Margin="0,-30,0,0" />
<TextBlock x:Name="ServingTitel"
TextWrapping="Wrap"
Text="{Binding name}"
FontSize="21.333"
Margin="50,-60,0,0" />
<Image x:Name="Ribbon"
HorizontalAlignment="Right"
Height="30"
VerticalAlignment="Top"
Width="151"
Source="/TEX/GrayRibbon.png"
Stretch="UniformToFill"
Margin="0,-60,0,0" />
<TextBlock x:Name="Kcal"
TextWrapping="Wrap"
Text="{Binding kalorien]}"
FontSize="18.667"
Height="23"
Margin="0,-92,8,0"
TextAlignment="Right" />
<Button Content="1"
Width="55" Height="55"
BorderThickness="3"
FontSize="18.667"
Padding="-1,-2,0,0"
Margin="-400,-87,0,0"
FontWeight="Bold"
Click="servingButtonClicked" />
</StackPanel>
</DataTemplate>
</ListBox>
You need to check your Margin values - in the main list you're putting 297 pixels of whitespace below your list box. Other elements have weird values too. Expression Blend sometimes messes with the Margins if you change from a StackPanel to a Grid.
e.g:
Margin="0,0,0,297">
I have a dock panel, with one label in the middle and another button on the far right.
Because of the button the label cannot align to the middle when the windows is maximized.
WPF:
<DockPanel Height="40" HorizontalAlignment="Stretch" Margin="-1,-2,0,0" Name="dockPanel1" VerticalAlignment="Stretch" Width="Auto" OpacityMask="{x:Null}">
<Label FontSize="18" Content="Sales" FontWeight="Bold" FontFamily="Arial" Width="883" Height="42" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Foreground="White" DockPanel.Dock="Left" VerticalAlignment="Center" VerticalContentAlignment="Center"></Label>
<Button FontSize="18" Height="47" Width="123" Name="btnStart" Foreground="White" BorderBrush="{x:Null}" FlowDirection="LeftToRight" HorizontalContentAlignment="Center" FontFamily="Arial Rounded MT" ClickMode="Press" DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="0" Content="Start" BorderThickness="0" Focusable="False">
</DockPanel>
Use a Grid instead of a DockPanel
Grid's allow objects to be placed on top of each other, so you can position your Label in the middle and the Button on the Right
<Grid>
<Label HorizontalAlignment="Center" VerticalAlignment="Center" />
<Button HorizontalAlignment="Right" />
</Grid>
Also if you're new to WPF's Layouts, I'd recommend reading through WPF Layouts: A Quick Visual Start so you know what layouts are available and can pick the best one for your sitaution
Hi
I have to add support for other languages in my application. Almost entire application is ready however I have a problem with translating a tooltip which is 'loaded' from resourcesDictioanry file.
For couple element in my application I have the same tooltip. So instead of writting the same code over and over again I decied to put a tooltip into ResourceDitionary.
My tooltip looks like that
<TextBlock FontWeight="Bold" Text="Text to translation" TextAlignment="Left" />
<TextBlock Text="{Binding Path=_Code}" Grid.Column="1" TextWrapping="Wrap"/>
<TextBlock FontWeight="Bold" Text="Text to translation" TextAlignment="Left" Grid.Row="1" />
<TextBlock Text="{Binding Path=_Name}" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap"/>
<TextBlock Text="Text to translation:" Grid.Row="3" FontWeight="Bold" TextAlignment="Left" />
</Grid>
</ToolTip>
What is the best way to implement multilanguage support from ResourcesDictionary ?
You should perhaps substitute
Text="Text to translation"
by
Text="{DynamicResource TOOLTIP_TEXT_ID}"
This recipy assumes your application's translation is resource dictionary-based, of course.