C
C#2y ago
Di0n

✅ Font Awesome in WPF

Hi I added Fontawesome Nugget Package to my WPF project (FontAwesome.Sharp) and when I try to add an Icon like <fa:IconImage Icon="AngleLeft"/> it gives me the following Severity Code Description Project File Line Suppression State Error XDG0003 Could not load file or assembly 'FontAwesome.Sharp, Version=6.3.0.0, Culture=neutral, PublicKeyToken=d16d1e4e568ec10f'. The system cannot find the file specified.
Any Fixes?
10 Replies
Klarth
Klarth2y ago
Never fully trust any XDG* errors as those are related to the designer. Build the app, try to run it, see what happens. Check the Build Output in the build fails.
Di0n
Di0nOP2y ago
Ohh it fixed icic tysm BowDown
Klarth
Klarth2y ago
I can't really tell you why this particular error happens. Sometimes you just need to rebuild, but sometimes the designer is just misleading. When I was using WPF, I preferred disabling the designer altogether because of these issues (and others) and instead use XAML Hot Reload for layout/styling.
Di0n
Di0nOP2y ago
that makes sense. btw since we on topic of WPF another quick question. I have the following <Image x:Name="ImageLogout" HorizontalAlignment="Left" Height="40" Margin="20,120,0,0" VerticalAlignment="Top" Width="40" Source="/Assets/Images/ImageLogout.png" Grid.Row="1"/> but hte image doesn't load even tho the source is correct (no error is given it just doesn't load)
Aurumaker72
Aurumaker722y ago
1. Did you make sure the element is being laid out correctly and is indeed visible? 2. Did you make sure the source is correct? (by loading an image in code-behind and breaking with the debugger to see it succeed)
Klarth
Klarth2y ago
Also, you need to set the Build Action of the image to Resource.
Di0n
Di0nOP2y ago
Yes I have put the image as Resource
<Grid x:Name="GridMenu" HorizontalAlignment="Left" Width="280" Margin="0,70,0,0" >
<Grid.RowDefinitions>
<RowDefinition Height="317*"/>
<RowDefinition Height="205"/>
</Grid.RowDefinitions>

<Button x:Name="ButtonAppointments" Opacity="0" Visibility="Hidden" Style="{DynamicResource StyleButtonMenu}" Content="Appointments" Height="40" VerticalAlignment="Top" FontFamily="Poppins" FontWeight="Normal" Margin="50,35,0,0"/>
<Button x:Name="ButtonMedicalRecords" Opacity="0" Visibility="Hidden" Style="{DynamicResource StyleButtonMenu}" Content="Medical Records" Height="40" VerticalAlignment="Top" FontFamily="Poppins" FontWeight="Normal" Margin="50,80,0,0"/>
<Button x:Name="ButtonLogout" Opacity="0" Visibility="Hidden" Style="{DynamicResource StyleButtonLogout}" Height="60" VerticalAlignment="Bottom" FontFamily="Poppins" FontWeight="Normal" Grid.Row="1">
<TextBlock TextAlignment="Center">Terminar<LineBreak/>Sessão</TextBlock>
</Button>

<Rectangle x:Name="RectangleAlterarMeio" Visibility="Hidden" HorizontalAlignment="Left" Height="40" Margin="-5,35,0,0" VerticalAlignment="Top" Width="12" Fill="White" RadiusX="5" RadiusY="5"/>


<Image x:Name="ImageAppointments" HorizontalAlignment="Left" Height="40" Margin="20,35,0,0" VerticalAlignment="Top" Width="40" Stretch="None" Source="/Assets/Images/ImageRegistos.png"/> --> Doesn't Load Image

<Image x:Name="ImageLogout" HorizontalAlignment="Left" Height="40" Margin="20,120,0,0" VerticalAlignment="Top" Width="40" Source="/Assets/Images/ImageLogout.png" Grid.Row="1"/>




</Grid>

<Image HorizontalAlignment="Left" Height="100" Margin="-20,182,0,0" VerticalAlignment="Top" Width="100" Source="/Assets/Images/ImageRegistos.png"/> -> Loads Image


</Grid>
<Grid x:Name="GridMenu" HorizontalAlignment="Left" Width="280" Margin="0,70,0,0" >
<Grid.RowDefinitions>
<RowDefinition Height="317*"/>
<RowDefinition Height="205"/>
</Grid.RowDefinitions>

<Button x:Name="ButtonAppointments" Opacity="0" Visibility="Hidden" Style="{DynamicResource StyleButtonMenu}" Content="Appointments" Height="40" VerticalAlignment="Top" FontFamily="Poppins" FontWeight="Normal" Margin="50,35,0,0"/>
<Button x:Name="ButtonMedicalRecords" Opacity="0" Visibility="Hidden" Style="{DynamicResource StyleButtonMenu}" Content="Medical Records" Height="40" VerticalAlignment="Top" FontFamily="Poppins" FontWeight="Normal" Margin="50,80,0,0"/>
<Button x:Name="ButtonLogout" Opacity="0" Visibility="Hidden" Style="{DynamicResource StyleButtonLogout}" Height="60" VerticalAlignment="Bottom" FontFamily="Poppins" FontWeight="Normal" Grid.Row="1">
<TextBlock TextAlignment="Center">Terminar<LineBreak/>Sessão</TextBlock>
</Button>

<Rectangle x:Name="RectangleAlterarMeio" Visibility="Hidden" HorizontalAlignment="Left" Height="40" Margin="-5,35,0,0" VerticalAlignment="Top" Width="12" Fill="White" RadiusX="5" RadiusY="5"/>


<Image x:Name="ImageAppointments" HorizontalAlignment="Left" Height="40" Margin="20,35,0,0" VerticalAlignment="Top" Width="40" Stretch="None" Source="/Assets/Images/ImageRegistos.png"/> --> Doesn't Load Image

<Image x:Name="ImageLogout" HorizontalAlignment="Left" Height="40" Margin="20,120,0,0" VerticalAlignment="Top" Width="40" Source="/Assets/Images/ImageLogout.png" Grid.Row="1"/>




</Grid>

<Image HorizontalAlignment="Left" Height="100" Margin="-20,182,0,0" VerticalAlignment="Top" Width="100" Source="/Assets/Images/ImageRegistos.png"/> -> Loads Image


</Grid>
Klarth
Klarth2y ago
So if it loads in one spot and not another, then the problem isn't image loading. Your problem is layout. This is another classic pitfall of the WPF designer: using Margin for positioning instead of proper use of layout containers. Margin is best used when you're pushing a control a few (maybe 20) pixels for minor spacing adjustments. Once you start pushing controls over each other and using Margin for absolute placement, your layouts will resize with very buggy behavior. I don't know if the XAML has been trimmed from the original to show us, but stuff like this doesn't make sense either:
<Grid.RowDefinitions>
<RowDefinition Height="317*"/>
<RowDefinition Height="205"/>
</Grid.RowDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="317*"/>
<RowDefinition Height="205"/>
</Grid.RowDefinitions>
The first row is 317 parts of proportional representation and the second row is 205 pixels...which doesn't make sense. Just do * and 205 if that's the case.
Di0n
Di0nOP2y ago
Ye I don't have much experiene in WPF and have been self learning so this type of issues is still new things to me. and the image fixed once I removed the 'Stretch' Ty for all help milkbow
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server