C
C#2y ago
Di0n

❔ Fontawesome icons dont support converting in WPF

Hi, im following a youtube tutorial on how to do a calendar UI and in one of the steps im supposed to make the following inside a UserControl
public partial class Items : UserControl
{
public Items()
{
InitializeComponent();
}



public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}

public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(MenuButton));

public string Time
{
get { return (string)GetValue(TimeProperty); }
set { SetValue(TimeProperty, value); }
}

public static readonly DependencyProperty TimeProperty =
DependencyProperty.Register("Time", typeof(string), typeof(MenuButton));


public SolidColorBrush Color
{
get { return (SolidColorBrush)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}

public static readonly DependencyProperty ColorProperty =
DependencyProperty.Register("Color", typeof(SolidColorBrush), typeof(MenuButton));


public FontAwesome.Sharp.Icon Icon
{
get { return (FontAwesome.Sharp.Icon)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}

public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon", typeof(FontAwesome.Sharp.Icon), typeof(MenuButton));

public FontAwesome.Sharp.Icon IconBell1
{
get { return (FontAwesome.Sharp.Icon)GetValue(IconBell1Property); }
set { SetValue(IconBell1Property, value); }
}

public static readonly DependencyProperty IconBell1Property =
DependencyProperty.Register("IconBell1", typeof(FontAwesome.Sharp.Icon), typeof(MenuButton));


}
public partial class Items : UserControl
{
public Items()
{
InitializeComponent();
}



public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}

public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(MenuButton));

public string Time
{
get { return (string)GetValue(TimeProperty); }
set { SetValue(TimeProperty, value); }
}

public static readonly DependencyProperty TimeProperty =
DependencyProperty.Register("Time", typeof(string), typeof(MenuButton));


public SolidColorBrush Color
{
get { return (SolidColorBrush)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}

public static readonly DependencyProperty ColorProperty =
DependencyProperty.Register("Color", typeof(SolidColorBrush), typeof(MenuButton));


public FontAwesome.Sharp.Icon Icon
{
get { return (FontAwesome.Sharp.Icon)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}

public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon", typeof(FontAwesome.Sharp.Icon), typeof(MenuButton));

public FontAwesome.Sharp.Icon IconBell1
{
get { return (FontAwesome.Sharp.Icon)GetValue(IconBell1Property); }
set { SetValue(IconBell1Property, value); }
}

public static readonly DependencyProperty IconBell1Property =
DependencyProperty.Register("IconBell1", typeof(FontAwesome.Sharp.Icon), typeof(MenuButton));


}
So basically after adding this new binding methods on the icons and text im getting errors on the icon converter -> Error XDG0028 The TypeConverter for "Icon" does not support converting from a string
5 Replies
Di0n
Di0nOP2y ago
XAML Code(didnt fit all in one message)
<Grid Margin="30 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<fa:IconImage Icon="{Binding Path=Icon, ElementName=item}" Width="20" Height="20" VerticalAlignment="Top" Foreground="#f1f1f1" Margin="0 3 0 0"/>

<StackPanel Grid.Column="1" Margin="10 0">
<TextBlock FontSize="16" Foreground="{Binding Path=Color, ElementName=item}" Text="{Binding Path=Title, ElementName=item}"/>

<StackPanel Orientation="Horizontal" Margin="0 5 0 0">
<fa:IconImage Grid.Column="2" Icon="{Binding Path=IconBell1, ElementName=item}" Width="12" Height="12" Foreground="{Binding Path=Color, ElementName=item}"/>

<TextBlock FontFamily="12" Foreground="{Binding Path=Color, ElementName=item}" Text="{Binding Path=Time, ElementName=item}" Margin="8 0 0 0"/>
</StackPanel>
</StackPanel>

<ToggleButton x:Name="buttonMenu" Grid.Column="2">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<fa:IconImage Icon="EllipsisV" Width="16" Height="16" Foreground="#f1f1f1">
<fa:IconImage.Style>
<Style TargetType="fa:IconImage">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1.2" ScaleY="1.2"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</fa:IconImage.Style>
</fa:IconImage>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>

<Popup IsOpen="{Binding IsChecked, ElementName=buttonMenu}" AllowsTransparency="True" StaysOpen="False" PlacementTarget="{Binding ElementName=buttonMenu}" Placement="Left"
VerticalOffset="30" HorizontalOffset="15">

<Border Background="White" CornerRadius="5" Padding="0 4">
<StackPanel>

<local:MenuButton Icon="Check" Caption="Check"/>
<local:MenuButton Icon="BellSlash" Caption="Mute"/>
<local:MenuButton Icon="Pencil" Caption="Edit"/>
<local:MenuButton Icon="Trash" Caption="Delete"/>

</StackPanel>
</Border>

</Popup>
</Grid>
<Grid Margin="30 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<fa:IconImage Icon="{Binding Path=Icon, ElementName=item}" Width="20" Height="20" VerticalAlignment="Top" Foreground="#f1f1f1" Margin="0 3 0 0"/>

<StackPanel Grid.Column="1" Margin="10 0">
<TextBlock FontSize="16" Foreground="{Binding Path=Color, ElementName=item}" Text="{Binding Path=Title, ElementName=item}"/>

<StackPanel Orientation="Horizontal" Margin="0 5 0 0">
<fa:IconImage Grid.Column="2" Icon="{Binding Path=IconBell1, ElementName=item}" Width="12" Height="12" Foreground="{Binding Path=Color, ElementName=item}"/>

<TextBlock FontFamily="12" Foreground="{Binding Path=Color, ElementName=item}" Text="{Binding Path=Time, ElementName=item}" Margin="8 0 0 0"/>
</StackPanel>
</StackPanel>

<ToggleButton x:Name="buttonMenu" Grid.Column="2">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<fa:IconImage Icon="EllipsisV" Width="16" Height="16" Foreground="#f1f1f1">
<fa:IconImage.Style>
<Style TargetType="fa:IconImage">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1.2" ScaleY="1.2"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</fa:IconImage.Style>
</fa:IconImage>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>

<Popup IsOpen="{Binding IsChecked, ElementName=buttonMenu}" AllowsTransparency="True" StaysOpen="False" PlacementTarget="{Binding ElementName=buttonMenu}" Placement="Left"
VerticalOffset="30" HorizontalOffset="15">

<Border Background="White" CornerRadius="5" Padding="0 4">
<StackPanel>

<local:MenuButton Icon="Check" Caption="Check"/>
<local:MenuButton Icon="BellSlash" Caption="Mute"/>
<local:MenuButton Icon="Pencil" Caption="Edit"/>
<local:MenuButton Icon="Trash" Caption="Delete"/>

</StackPanel>
</Border>

</Popup>
</Grid>
Any Solutions?
Aurumaker72
Aurumaker722y ago
I recommend not hacking in Fontawesome icons, but using a library integrated with WPF instead https://github.com/MahApps/MahApps.Metro.IconPacks
Di0n
Di0nOP2y ago
wdym by hacking? I used a nugget package available on VS and how does the GitHub repo fix my issue?<a:ChillBar_confused:1001503745361858590>
Aurumaker72
Aurumaker722y ago
The Icon dp is confusing, could you clarify what the requirement is?
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