I am attempting to use Font Awesome in a WPF app. It half works. That is, some glyphs are picked up and show, others show a rectangle.
I'm following guides correctly, I think, but something is going wrong!
Here's a code snippet
<Window.Resources>
<FontFamily x:Key="FontAwesomeRegular">Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free Regular</FontFamily>
<FontFamily x:Key="FontAwesomeBrands">Fonts/Font Awesome 5 Brands-Regular-400.otf#Font Awesome 5 Brands Regular</FontFamily>
<FontFamily x:Key="FontAwesomeSolid">Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free Solid</FontFamily>
</Window.Resources>
<Grid>
<StackPanel Orientation="Vertical">
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="" HorizontalAlignment="Left" Foreground="Red" Margin="0" TextWrapping="Wrap" VerticalAlignment="Center" FontSize="100"/>
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="" HorizontalAlignment="Left" Foreground="Red" Margin="0" TextWrapping="Wrap" VerticalAlignment="Center" FontSize="100"/>
</StackPanel>
</Grid>
The fonts are installed in a Fonts directory
And Marked as Resource
And this is what it shows on the screen
You can see that the first icon xf15c; displays as expected but the second one xf15a; does not. Generally, most do not display.
Why?
If you open the .otf file, you can see the name of the font. This is what you need to use to the FontFamily resource, without the file extension.
Try the following code:
<FontFamily x:Key="Icons">pack://application:,,,/{YOUR PROJECT NAME};component/Fonts/#Font Awesome 5 Free Solid</FontFamily>
Related
I'm trying to add a custom font to my application, but I'm getting an error:
An object of the type "System.Windows.Style" cannot be applied to a property that expects the type "System.Windows.Media.FontFamily".
From the error, I'm guessing that it means, the font wasn't imported, but I'm not sure why it wasn't.
Here's the code in the MainWindow.xaml file:
<Window.Resources>
<Style x:Key="Raleway">
<Setter Property="TextElement.FontFamily" Value="fonts/#Raleway"/>
</Style>
</Window.Resources>
<TextBlock Text="text"
FontWeight="Light"
FontFamily="{StaticResource Raleway}"
FontSize="22"
Foreground="White"
HorizontalAlignment="Center"
/>
This is my directory:
The following markup shows how to reference the application's font resources:
<Window.Resources>
<FontFamily x:Key="Raleway">./fonts/#Raleway</FontFamily>
</Window.Resources>
<TextBlock Text="text"
FontWeight="Light"
FontFamily="{StaticResource Raleway}"
FontSize="22"
Foreground="White"
HorizontalAlignment="Center"
/>
When you add fonts as resources to your application, make sure you are setting the <Resource> element, and not the <EmbeddedResource> element in your application's project file. The <EmbeddedResource> element for the build action is not supported.
It is possible to package fonts with WPF application. The detailed information is here: Packaging Fonts with Applications
I have a MahApps progress indicator declared like this:
<Controls:ProgressIndicator ProgressColour="{StaticResource AccentColorBrush}" Width="600" Height="20" VerticalAlignment="Top" HorizontalAlignment="Stretch"
Visibility="{Binding ElementName=Self, Path=DataContext.ShowProgress, Converter={StaticResource b2v}, FallbackValue=Visible}"/>
And for some reason the indicator bars do not stretch the size of the control. It only fills about 20% of the width. (I can't show a picture as my reputation is too low).
Has anyone experienced this before?
Cheers
Edit
The indicator is on a stackpanel declared like this:
<StackPanel Grid.Column="2" Grid.ColumnSpan="6" Orientation="Vertical">
Update:
In the latest version from nuget or Github ProgressIndicator seems to be removed(cos it was buggy).
Pull request that removed the control early this year
This release, again, contains some breaking changes. We try to break things now rather than later, when we release version 1.0 (which is hopefully soon).
A quick overview:
ProgressIndicator is now removed, as it wasn't working as expected. Use MetroProgressBar with IsIndeterminate = True instead, which should give a much smoother experience.
I just tried the sample with
<Controls:MetroProgressBar Width="300"
Margin="0, 10, 0, 0"
Foreground="{DynamicResource AccentColorBrush}"
IsIndeterminate="True"
Maximum="100"
Minimum="0" />
I recently upgraded my WPF project from .NET v3.5 to v4.0 and I'm still running into issues where all of my text is blurry. I have the following set in my main window.
TextOptions.TextRenderingMode="ClearType"
TextOptions.TextFormattingMode="Display"
From what I've read this issue was fixed in WPF 4.
Here is what it looks like using the following markup.
<TextBlock Text="Sample with TextOptions..."
FontFamily="Arial, sans-serif"
FontSize="14"
TextOptions.TextRenderingMode="ClearType"
TextOptions.TextFormattingMode="Display" />
<TextBlock Text="Sample without TextOptions..."
FontFamily="Arial, sans-serif"
FontSize="14" />
While I can definetly see a difference in text, it still isn't as clear as I would expect it to be. Am I just crazy!?
I am developing an application where i want to browse images like native WindowsPhone form.
I have used Pivot control. Everything works, but there is one unwanted thing. The image does not fill all display area. There is a gap on the top of page. I have set margin and padding everywhere where it is possible. And the result is still the same. :(
Here is my XAML code:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid
x:Name="LayoutRoot"
Background="Transparent"
Margin="0">
<toolkit:PerformanceProgressBar
VerticalAlignment="Top"
HorizontalAlignment="Left"
IsIndeterminate="{Binding IsBusy}"
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibilityConverter}}"
/>
<controls:Pivot
x:Name="PhotoPivot"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
IsHitTestVisible="True"
ItemsSource="{Binding Photos}"
Margin="0"
Padding="0"
>
<controls:Pivot.HeaderTemplate>
<DataTemplate/>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate >
<controls:PivotItem
x:Name="PhotoPivotItem"
Margin="0"
>
<Image
x:Name="PhotoPicture"
Source="{Binding}"
Stretch="Uniform"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0"
/>
</controls:PivotItem>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
</Grid>
Are you talking about the system tray?
To remove the system tray use the following code:
shell:SystemTray.IsVisible="False"
Update:
I'm not real sure why that extra space is there.
I created a simplified version of your example and the only thing I could think of is to use negative margins. There is probably a better solution that I am just overlooking, but for now you can just use the following:
<controls:PivotItem x:Name="PhotoPivotItem" Margin="0,-10,0,0">
Although, from your posted image, it looks as if you have a bigger gap than I did, so you might need to decrease the margin.
I am using a textblock to display the product description under the product's image. The text must be fixed 100px wide but the height can grow up to 30px tall. If the text still can't fit, it must display ellipsis. Here is my xaml:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" .../>
<Canvas/>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="{Binding Path=ProductDescription}"
HorizontalAlignment="Center" VerticalAlignment="Top" TextAlignment="Center">
</StackPanel>
The description can have multiple lines. For eg, "Wireless Mouse\nQuantity:20". It looks ok on XP but on Windows 7 only the first line shows up and there's no ellipsis. Can anyone spot the problem in my xaml?
There are several errors in your example: should , ".../>" isn't valid XAML and your TextBlock doesn't have a closing tag.
The follow XAML worked fine on for me on Windows 7:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" />
</Canvas>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="I use canvas here to reserve some space for animation (grow/shrink)"
HorizontalAlignment="Center"
VerticalAlignment="Top"
TextAlignment="Center" />
</StackPanel>
Depending on the font size MaxHeight of 30 is almost just one line of text, so the textblock can't grow in height. Change it or remove it completely.