gpt4 book ai didi

c# - XAML 将 Rectange.Fill SolidColorBrush 绑定(bind)到 Color 属性

转载 作者:行者123 更新时间:2023-11-30 16:15:34 26 4
gpt4 key购买 nike

我正在尝试显示一个 TextBox 和一个 Rectangle,它们都在另一个类中显示 Color 属性。我使用 Caliburn.Micro 和 MVVM 方法(我是新手)。

我的问题是 TextBox 默认写入 Color.ToString,但 Rectangle 不会填充相同的 Color,实际上矩形一直是不可见的。如何填写?

从 XAML View 中提取:

<TextBox Grid.Row="7" Grid.Column="1" Margin="10,7,20,7"
Text="{Binding Path=Design.EdgeHighlightOutOfRangeColor}"
FontSize="12" FontFamily="Rockwell" Width="110" HorizontalAlignment="Left"/>
<Rectangle Grid.Row="7" Grid.Column="1" Width="20" Height="20" Margin="100,7,20,7">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Path=Design.EdgeHighlightOutOfRangeColor}"/>
</Rectangle.Fill>
</Rectangle>

从 C# ViewModel 中提取:

_designSettings = _settings.DesignSettings;
public DesignSettings Design
{
get { return _designSettings; }
set
{
_designSettings = value;
NotifyOfPropertyChange(() => Design);
}
}

在 DesignSettings 类中,我有这个属性要绑定(bind):

public Color EdgeHighlightOutOfRangeColor { get; set; }

最佳答案

除非您为 Color 属性使用了错误的命名空间,否则您的代码应该可以正常工作。

颜色可以在System.Drawing下找到和 System.Windows.Media.Colors .确保您使用的是 System.Windows.Media 以便将其与 Rectangle 绑定(bind)。

有了System.Drawing,它会像下面这样;无填充矩形

enter image description here

关于c# - XAML 将 Rectange.Fill SolidColorBrush 绑定(bind)到 Color 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19445422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com