【发布时间】:2015-07-17 17:00:22
【问题描述】:
我以前看过一些答案,但没有什么能真正帮助我。
我还有一个类DecideModel(这将是从数据库中检索到的数据集,但出于这个问题的目的,我添加了一个 ObservableCollection),其中包含
static DecideModel()
{
All = new ObservableCollection<DecideModel>
{
new DecideModel
{
DatePerformed = new DateTime(2015, 4, 06),
Result = "Maybe"
},
new DecideModel
{
DatePerformed = new DateTime(2015, 4, 05),
Result = "No"
},
new DecideModel
{
DatePerformed = new DateTime(2015, 4, 04),
Result = "Yes"
}
};
}
public DateTime DatePerformed { set; get; }
public string Result { set; get; }
public static IList<DecideModel> All { set; get; }
}
在我的 XAML 代码中
<ContentPage.Resources>
<ResourceDictionary>
<Color x:Key="Maybe">#ffddbc21</Color>
<Color x:Key="Yes">#3CB371</Color>
<Color x:Key="No">#B22222</Color>
<Color x:Key="Depends">#ffd78800</Color>
</ResourceDictionary>
</ContentPage.Resources>
<Label Text="{Binding Result}" HorizontalOptions="FillAndExpand" BackgroundColor="{StaticResource {BindingSource Result}}" />
我正在尝试根据我从对象获得的结果动态设置标签的背景颜色。
如果您对如何操作有任何想法,请告诉我。我正在寻找任何可用的有用选项。
【问题讨论】:
标签: xaml binding xamarin xamarin.forms