将毛伊岛控制背景色绑定到具有数据类型系统的属性。drawing.Color
我有一个带有颜色属性的类,该类别是数据类型system.drawing.color,它用于绑定Windows表单控件,我想将MAUI控制背景色绑定到它。毛伊岛控制背景颜色的数据类型是microsoft.maui.graphics.color。当我尝试将毛伊岛控制直接绑定到颜色时,控制背景颜色只是灰色。这是因为数据类型不同而被理解的。我尝试将属性添加到将颜色返回字符串的类中,我对此的想法是,绑定以颜色名称为字符串,因此它应该能够绑定到字符串属性。它也没有起作用。
//class properties
public Color ShapeColor
{
get {
return colorval;
}
set
{
colorval = value;
InvokePropertyChanged();
InvokePropertyChanged("ShapeColorToString");
}
}
public string ShapeColorToString { get { return this.ShapeColor.ToString(); } }
以下与颜色绑定不起作用:
<Button x:Name="btn1"BackgroundColor="{Binding Path=ShapeColor}" />
颜色也没有像字符串一样绑定:
<Button x:Name="btn2" BackgroundColor="{Binding Path=ShapeColorToString}"/>
I have a class with a Color property that is data type System.Drawing.Color, it is used for binding a Windows Forms control, and I want to bind a MAUI control BackgroundColor to it. The data type for the MAUI control background color is Microsoft.Maui.Graphics.Color. When I try binding the MAUI control straight to the Color, the control background color is just gray. That is understood because the data types are different. I tried adding a property to the class which returns the color as a string, my thinking on that was that the Binding takes a color name as a string, so it should be able to bind to a string property. It did not work either.
//class properties
public Color ShapeColor
{
get {
return colorval;
}
set
{
colorval = value;
InvokePropertyChanged();
InvokePropertyChanged("ShapeColorToString");
}
}
public string ShapeColorToString { get { return this.ShapeColor.ToString(); } }
the following bound to Color did not work:
<Button x:Name="btn1"BackgroundColor="{Binding Path=ShapeColor}" />
nor did binding to color as string work:
<Button x:Name="btn2" BackgroundColor="{Binding Path=ShapeColorToString}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,我拥有的最好的解决方案是:将Microsoft.maui.graphics安装到类库中(当前预览,因此请确保您在Nuget浏览中包含Preview)。然后添加一个将system.color转换为microsoft.maui.graphics.color的属性:
我宁愿不在类库中安装Maui Graphics,但这是我能想到的最好的。
The best solution I have so far is: Install Microsoft.Maui.Graphics into the class library (currently preview, so ensure that you include preview in the NuGet browse). And then add a property that converts System.Drawing.Color to Microsoft.Maui.Graphics.Color as so:
I would rather not install MAUI graphics in the class library, but that is the best I can come up with.