将画笔转换为字符串以保存在EF中

时间:2014-04-17 16:09:22

标签: wpf entity-framework tostring brush

我正在创建一个包含日历事件的应用程序,以便用户有效使用。作为功​​能的一部分,我希望用户能够将颜色保存到他们添加的事件中。即;将事件的背景设置为红色。

到目前为止,我正在使用来自WPFToolKit的colourpicker,我绑定到brush属性,就像这样;

<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"/>

但是,因为我使用的是数据库,所以我不确定保存画笔的最佳方法是什么。我已经研究过使用this universal converter,但不幸的是它似乎没有用。

我试图按照这样的方式将画笔保存到数据库中;

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

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

但它会抛出以下信息; Object reference not set to an instance of an object.

因此,对我来说最好的选择是什么?在保存之前,最好将Brush转换为字符串吗?如果是的话,怎么办呢?

1 个答案:

答案 0 :(得分:0)

您的Color为空。你想在那里检查是否为空。

相关问题