<customcontrol:IconButton Width="100" Height="100"
iconCode=""
Type="AddButtonStyle"/>
<customcontrol:IconButton Width="100" Height="100"
iconCode=""
Type="AddButtonStyle"/>
/// <summary>
/// Custom Control for an icon in a small button
/// </summary>
public sealed partial class IconButton : Button
{
/// <summary>
/// icon code to add to the button
/// </summary>
public string IconCode { get; set; } = string.Empty;
/// <summary>
/// Type of the Style to apply on the Button
/// </summary>
public CustomButtonType Type { get; set; }
/// <summary>
///
/// </summary>
public IconButton()
{
this.DefaultStyleKey = typeof(IconButton);
}
/// <summary>
///
/// </summary>
protected override void OnApplyTemplate()
{
try
{
base.OnApplyTemplate();
}catch
{
Console.WriteLine("error base.OnApplyTemplate");
}
try
{
switch (Type)
{
case CustomButtonType.AccentButtonStyle:
this.Style = FournierStyles.MainStyles["AccentButtonStyle"] as Style;
break;
case CustomButtonType.AddButtonStyle:
this.Style = FournierStyles.ButtonStyles["AddButtonStyle"] as Style;
break;
case CustomButtonType.PrincipalButtonStyle:
this.Style = FournierStyles.ButtonStyles["PrincipalButtonStyle"] as Style;
break;
case CustomButtonType.DangerButtonStyle:
this.Style = FournierStyles.ButtonStyles["DangerButtonStyle"] as Style;
break;
case CustomButtonType.SecondaryButtonStyle:
this.Style = FournierStyles.ButtonStyles["SecondaryButtonStyle"] as Style;
break;
case CustomButtonType.WarningButtonStyle:
this.Style = FournierStyles.ButtonStyles["WarningButtonStyle"] as Style;
break;
case CustomButtonType.InfoButtonStyle:
this.Style = FournierStyles.ButtonStyles["InfoButtonStyle"] as Style;
break;
case CustomButtonType.SucessButtonStyle:
this.Style = FournierStyles.ButtonStyles["SucessButtonStyle"] as Style;
break;
case CustomButtonType.DefaultButtonStyle:
default:
break;
}
}
catch (Exception ex)
{
throw new StyleTypeException("Impossible to set Style to button for " + ex);
}
try
{
FontIcon icon = new()
{
Glyph = IconCode,
Foreground = new SolidColorBrush(Colors.Black)
};
this.Content = icon;
this.UpdateLayout();
this.Width = 30;
this.Height = 30;
}
catch (Exception ex)
{
throw new IconButtonGenerationException("Impossible to creation icon to IconButton because " + ex);
}
}
}
/// <summary>
/// Custom Control for an icon in a small button
/// </summary>
public sealed partial class IconButton : Button
{
/// <summary>
/// icon code to add to the button
/// </summary>
public string IconCode { get; set; } = string.Empty;
/// <summary>
/// Type of the Style to apply on the Button
/// </summary>
public CustomButtonType Type { get; set; }
/// <summary>
///
/// </summary>
public IconButton()
{
this.DefaultStyleKey = typeof(IconButton);
}
/// <summary>
///
/// </summary>
protected override void OnApplyTemplate()
{
try
{
base.OnApplyTemplate();
}catch
{
Console.WriteLine("error base.OnApplyTemplate");
}
try
{
switch (Type)
{
case CustomButtonType.AccentButtonStyle:
this.Style = FournierStyles.MainStyles["AccentButtonStyle"] as Style;
break;
case CustomButtonType.AddButtonStyle:
this.Style = FournierStyles.ButtonStyles["AddButtonStyle"] as Style;
break;
case CustomButtonType.PrincipalButtonStyle:
this.Style = FournierStyles.ButtonStyles["PrincipalButtonStyle"] as Style;
break;
case CustomButtonType.DangerButtonStyle:
this.Style = FournierStyles.ButtonStyles["DangerButtonStyle"] as Style;
break;
case CustomButtonType.SecondaryButtonStyle:
this.Style = FournierStyles.ButtonStyles["SecondaryButtonStyle"] as Style;
break;
case CustomButtonType.WarningButtonStyle:
this.Style = FournierStyles.ButtonStyles["WarningButtonStyle"] as Style;
break;
case CustomButtonType.InfoButtonStyle:
this.Style = FournierStyles.ButtonStyles["InfoButtonStyle"] as Style;
break;
case CustomButtonType.SucessButtonStyle:
this.Style = FournierStyles.ButtonStyles["SucessButtonStyle"] as Style;
break;
case CustomButtonType.DefaultButtonStyle:
default:
break;
}
}
catch (Exception ex)
{
throw new StyleTypeException("Impossible to set Style to button for " + ex);
}
try
{
FontIcon icon = new()
{
Glyph = IconCode,
Foreground = new SolidColorBrush(Colors.Black)
};
this.Content = icon;
this.UpdateLayout();
this.Width = 30;
this.Height = 30;
}
catch (Exception ex)
{
throw new IconButtonGenerationException("Impossible to creation icon to IconButton because " + ex);
}
}
}
