0

Im creating an application that has incorporated a calendar event for users to effectively use. As part of the features, I want the user to be able to save a colour to the event that they add. i.e; set the background of the event to red.

So far, I am using a colourpicker from the WPFToolKit, to which i bind to the brush property, like so;

<xceed:ColorPicker SelectedColor="{Binding CurrentEvent.Color, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="200"
AvailableColorsHeader="Knowned appointments"DisplayColorAndName="True" ShowAvailableColors="True" ShowStandardColors="True" ShowAdvancedButton="False" UsingAlphaChannel="False"/>

However, because I am using a database, I am not to sure what the best approach is to save the brush. I have looked into using this universal converter but unfortunately it doesn't seem to work.

I have tried to following to save the brush to the database like so;

using (var context = new DBEntities())
        {
            //...
            app.Colour = a.Color.ToString();

            context.AddToAppointments(app);
            context.SaveChanges();
        }

But it throws the following message; Object reference not set to an instance of an object.

Therefore, what would be the best option for me to go around? Would it best for me to convert the Brush to a string before saving it? and if so, how could this be done?

greg
  • 1,289
  • 2
  • 14
  • 33
  • Color.ToString() would propably only return the type definition of you object, dont think that the tostring is overridden. You should save the HEX or RGB code. http://stackoverflow.com/questions/2395438/convert-system-drawing-color-to-rgb-and-hex-value – Rand Random Apr 17 '14 at 18:18

1 Answers1

0

Your Color is null. You want to check for null there.

123 456 789 0
  • 10,565
  • 4
  • 43
  • 72