It try to change a ForeColor or Backcolor with a color which is defined in another seperated xaml file. If i use this:
_toolTip.ForeColor = (Color)Application.Current.Resources["Color_001"];
I will get a exception thrown at the start of the programm: System.InvalidCastException: "Specified cast is not valid."
If i use this:
_toolTip.ForeColor = Resources["Color_001"] as Color;
It tells me that the class Color does not allow Null and cant be referenced with as-operater.
Is there a way i missed out?
Code in ColorBrush.xaml
<Color x:Key="Color_001">#FFFFFFFF</Color>
Code in App.xaml
<Application.Resources>
<ResourceDictionary >
<ResourceDictionary.MergedDictionaries >
<ResourceDictionary Source="pack://application:,,,/ColorBrush.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Code in App.xaml.cs
private void DesignToolTip(string tooltipText)
{
_toolTip = new System.Windows.Forms.ToolTip();
_toolTip.OwnerDraw = true;
_toolTip.UseAnimation = true;
_toolTip.Draw += GetToolTipDraw;
_toolTip.Popup += GetToolTipPopUp;
_toolTip.ToolTipTitle = tooltipText;
_toolTip.AutoPopDelay = 500;
_toolTip.AutomaticDelay = 500;
_toolTip.ForeColor = (Color)Application.Current.Resources["Color_001"];
//_toolTip.ForeColor = Resources["Color_001"] as Color;
//_toolTip.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FFFFFFFF");
_toolTip.BackColor = System.Drawing.ColorTranslator.FromHtml("#FF181818");
}
Make sure you're casting to the right Color class :
//Yep, working
System.Windows.Media.Color color1 = (System.Windows.Media.Color)Application.Current.Resources["Color_001"];
//Works too
System.Windows.Media.Color? color2 = Application.Current.Resources["Color_001"] as System.Windows.Media.Color?;
//InvalidCastException
System.Drawing.Color color3 = (System.Drawing.Color)Application.Current.Resources["Color_001"];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments