【问题标题】:Binding colors of shapes with variables c#用变量c#绑定形状的颜色
【发布时间】:2011-07-27 18:21:43
【问题描述】:

如果我有转换器,我如何在 c# 代码中绑定矩形的颜色和我的 bool ?我在 xaml 中没有矩形,我只是在代码中创建它并在网格上添加。

【问题讨论】:

  • 我想根据布尔变量的值来改变矩形的颜色。我已经有转换器可以将此布尔变量转换为颜色,但我不知道如何绑定它。

标签: c# xaml binding colors


【解决方案1】:

See your other question

在代码中添加绑定:

    Binding binding = new Binding("State");
    binding.Converter = new BooleanToBrushConverter();
    _rectangle.SetBinding(Rectangle.FillProperty, binding);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多