如何将图像可见性绑定到用户 属性
How to bind image visibility to user property
我正在使用 Xamarin Studio 处理 Xamarin Forms。
我在绑定图像可见性时遇到问题,如下所示。请建议我做一些改变。提前致谢。
var radiobtn_preference = new CircleImage {
BorderColor = ColorResources.commonButtonBackgroundColor,
HeightRequest = 25,
WidthRequest = 25,
Aspect = Aspect.AspectFill,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Source="radio_uncheck.png",
};
radiobtn_preference.SetBinding (radiobtn_preference.IsVisible, "isExcluded");
public class table
{
public 字符串名称{ get;放; }
public 字符串id{ get;放;}
public bool isExcluded{ 得到;放;}
}
public static class tableData
{
public static List<table> GetData ()
{
return new List<table> {
new table () {
Name="Peru",isExcluded=true,
},
new table () {
Name="Apple",isExcluded=false,
},
new table () {
Name="Grapes",isExcluded=true,
},
};
}
}
我声明图像并尝试将其可见性绑定到用户设置的 属性。
根据评论推断,您的代码中存在错误:
radiobtn_preference.SetBinding (radiobtn_preference.IsVisible, "isExcluded");
应该是
radiobtn_preference.SetBinding (CircleImage.IsVisibleProperty, "isExcluded");
注意第一个参数发生了怎样的变化。此参数应该是您要绑定的 属性 的标识符,而不是实际实例化的 属性。
如果要绑定到 Grid
,请注意您必须使用 Grid.IsVisibleProperty
。或者,如果您想绑定另一个 属性,例如 IsEnabled
属性,则必须使用 CircleImage.IsEnabledProperty
标识符。
我正在使用 Xamarin Studio 处理 Xamarin Forms。 我在绑定图像可见性时遇到问题,如下所示。请建议我做一些改变。提前致谢。
var radiobtn_preference = new CircleImage {
BorderColor = ColorResources.commonButtonBackgroundColor,
HeightRequest = 25,
WidthRequest = 25,
Aspect = Aspect.AspectFill,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Source="radio_uncheck.png",
};
radiobtn_preference.SetBinding (radiobtn_preference.IsVisible, "isExcluded");
public class table { public 字符串名称{ get;放; } public 字符串id{ get;放;} public bool isExcluded{ 得到;放;} }
public static class tableData
{
public static List<table> GetData ()
{
return new List<table> {
new table () {
Name="Peru",isExcluded=true,
},
new table () {
Name="Apple",isExcluded=false,
},
new table () {
Name="Grapes",isExcluded=true,
},
};
}
}
我声明图像并尝试将其可见性绑定到用户设置的 属性。
根据评论推断,您的代码中存在错误:
radiobtn_preference.SetBinding (radiobtn_preference.IsVisible, "isExcluded");
应该是
radiobtn_preference.SetBinding (CircleImage.IsVisibleProperty, "isExcluded");
注意第一个参数发生了怎样的变化。此参数应该是您要绑定的 属性 的标识符,而不是实际实例化的 属性。
如果要绑定到 Grid
,请注意您必须使用 Grid.IsVisibleProperty
。或者,如果您想绑定另一个 属性,例如 IsEnabled
属性,则必须使用 CircleImage.IsEnabledProperty
标识符。