Ok so I've added this code for Binding Color converter inside Application.Resources in App.xaml:
xmlns:converter="clr-namespace:FtpUploader2.Converters"
<converter:MessageTypeEnumToColor x:Key="MessageTypeEnumToColor"/>
I get no error messages and the program compiles just fine and it changes the different colors on my message element until I added the PrintMessage() function at a line in my code.
<Label Content="{Binding Text}"
Background="{Binding MessageType, Converter={StaticResource MessageTypeEnumToColor}}"/>
Print message to wpf viewlist:
public void PrintMessage(string a_message, Model.Message.MsgType a_msgType = Model.Message.MsgType.Information)
{
Model.Message message = new Model.Message(a_message, a_msgType);
Messages.Insert(0, message);
}
I've used the PrintMessage funtion just fine many times in the application. Now comes the part I can't figure out why it happens.
In a function called HandleUploadTabSelected()
PrintMessage("Failed to upload one or more accounts", Model.Message.MsgType.Error);
causes the error message in title:
Error 1 The tag 'MessageTypeEnumToColor' does not exist in XML namespace 'clr-namespace:FtpUploader2.Converters'. Line 7 Position 10.
EDIT: After testing Mike's suggestion it doesn't compile at all. Adding ;assembly=FtpUploader2
Here's the code for MessageTypeEnumToColor:
using FtpUploader2.Model;
namespace FtpUploader2.Converters
{
class MessageTypeEnumToColor : IValueConverter
{
#region IValueConverter Member
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Message.MsgType tempMsg = (Message.MsgType)value;
Brush retval;
switch (tempMsg)
{
case Message.MsgType.Ok:
retval = Brushes.Green;
break;
case Message.MsgType.Warning:
retval = Brushes.Yellow;
break;
case Message.MsgType.Error:
retval = Brushes.Red;
break;
default:
retval = Brushes.White;
break;
}
return retval;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}
确保应用程序的目标框架 (属性>应用程序>目标框架)与目标程序集的框架相同(例如:.NET Framework 4.7.2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.