将 SolidColorBrush 从 ViewModel 绑定到 DataGridCell/CellStyle

发布于 2024-09-28 11:40:59 字数 218 浏览 0 评论 0原文

我有一个具有属性 int DepartmentColor 的 ViewModel。当然,我无法将 int 值绑定到 XAML 中的 CellStyle。

我应该制作一个 IntToStyleConverter 还是应该摸索 ViewModel 中的 Style 类,例如将 int 转换为 SolicColorBrush 并将其分配给 Style 等...

后者是使用 MVVM 的方法吗?

I have a ViewModel with Property int DepartmentColor. Of course I can not bind the int value to a CellStyle in XAML.

Should I make a IntToStyleConverter or should I fumble around with the Style class in the ViewModel like convert the int to a SolicColorBrush and assign it to a Style etc...

Is the latter the way to go with MVVM ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小ぇ时光︴ 2024-10-05 11:40:59

走转换器路线。此外,我会将该属性命名为“Department”,而不是为其绑定颜色,因为这样可以使其与 UI 的耦合更加紧密。虽然会计部门可能会将其与颜色耦合,这意味着您确定它将通过颜色表示,而下游它可能会以其他视觉方式表示。您还可以提前创建样式,然后只需选择一种样式并通过转换器应用它,而不是尝试在后面的代码中创建它们。

Go the converter route. In addition I would title the property something to the effect of Department and not tie color to it as it makes it more tightly coupled to the UI. While the department may be Accounting coupling that to a color implies you are certain that it will be represented via a Color, whereas down stream it may be represented in some other visual fashion. You could also create the styles ahead of time and then simply select one and apply it via the converter, versus trying to create them in the code behind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文