【问题标题】:Convert Brush to String to Save in EF将画笔转换为字符串以保存在 EF 中
【发布时间】:2014-04-17 16:09:21
【问题描述】:

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

到目前为止,我正在使用 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.

因此,对我来说最好的选择是什么?在保存之前将画笔转换为字符串对我来说最好吗?如果是这样,如何做到这一点?

【问题讨论】:

标签: wpf entity-framework tostring brush


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2010-09-27
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    • 2012-10-24
    • 2017-08-19
    相关资源
    最近更新 更多