【发布时间】: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.
因此,对我来说最好的选择是什么?在保存之前将画笔转换为字符串对我来说最好吗?如果是这样,如何做到这一点?
【问题讨论】:
-
Color.ToString() 可能只会返回对象的类型定义,不要认为 tostring 被覆盖。您应该保存 HEX 或 RGB 代码。 stackoverflow.com/questions/2395438/…
标签: wpf entity-framework tostring brush