[英]How to pass collection to binding converter parameter in silverlight
In silverlight application in c# code I'm taking data from WCF RIA services. 在C#代码的Silverlight应用程序中,我从WCF RIA服务获取数据。 Then I want to pass this data (List) to chart (System.Windows.Forms.DataVisualization.Charting.Chart) axis converter parameter. 然后,我想将此数据(列表)传递到图表(System.Windows.Forms.DataVisualization.Charting.Chart)轴转换器参数。
this.specialDayClient = new SpecialDayClient();
this.specialDayClient.SpecialDayLoaded += new EventHandler(specialDayClient_SpecialDaysLoaded);
this.specialDayClient.SpecialDayLoadFailed += new EventHandler(specialDayClient_SpecialDaysLoadFailed);
private void specialDayClient_SpecialDaysLoaded(object sender, EventArgs e)
{
specialDays = sender as IEnumerable<SpecialDay>;
var binding = new Binding("ConverterBinding")
{
Converter = new DateToColorConverter(),
ConverterParameter = specialDays
};
var setter = new Setter(ForegroundProperty, binding);
((DateTimeAxis)chartCashRemainders.Axes[0]).AxisLabelStyle.Setters.Add(setter);
//After this row I get error message "Error HRESULT E_FAIL has been returned from a call to a COM component."
}
private void specialDayClient_SpecialDaysLoadFailed(object sender, EventArgs e)
{
specialDays = new List<SpecialDay>();
}
After ((DateTimeAxis)chartCashRemainders.Axes[0]).AxisLabelStyle.Setters.Add(setter); 之后((DateTimeAxis)chartCashRemainders.Axes [0])。AxisLabelStyle.Setters.Add(setter); I'm getting error message "Error HRESULT E_FAIL has been returned from a call to a COM component." 我收到错误消息“对COM组件的调用已返回错误HRESULT E_FAIL。”
Where is my mistake? 我的错误在哪里?
Ok, the simplest way - create a new class with object collection: 好的,最简单的方法-使用对象集合创建一个新类:
public class SpecialDays : List<SpecialDay>
{
public SpecialDays()
{
if(DesignerProperties.IsInDesignTool)
return;
DeviceManagementDomainContext domainContext = new DeviceManagementDomainContext();
var query = domainContext.GetSpecialDaysForEditorQuery();
LoadOperation<SpecialDay> operation = domainContext.Load(query);
operation.Completed += (s, e) =>
{
if (operation.HasError)
{
if (operation.Error != null)
{
operation.MarkErrorAsHandled();
}
this.AddRange(new List<SpecialDay>());
}
else
{
List<SpecialDay> specialDays = operation.Entities.ToList();
this.AddRange(specialDays);
}
};
}
}
Then add this class in xaml code (to ): 然后在xaml代码中添加此类(至):
<UserControl.Resources>
<bs2Models:SpecialDays x:Key="SpecialDays"/>
</UserControl.Resources>
And add as static resource to converter: 并将其作为静态资源添加到转换器:
<Style x:Key="HorizontalAxisLabelStyle" TargetType="toolkit:DateTimeAxisLabel">
<Setter Property="Foreground" Value="{Binding Converter={StaticResource DateToColorConverter}, ConverterParameter={StaticResource SpecialDays}}"/>
</Style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.