I have开发者_JS百科 an anonymous linq query that I bind to a datagrid, when I debug it brings alright the data but it doesn't show in the datagrid, I suspect that the request to RIA services isn't completed before I bound it to the datagrid. I could use the LoadOperation<>() Completed event. But it only works with Defined Entities so how can I do that? For reference here is the last post: LINQ query null reference exception Here is the query:
var bPermisos = from b in ruc.Permisos
where b.IdUsuario == SelCu.Id
select new {
Id=b.Id,
IdUsuario=b.IdUsuario,
IdPerfil=b.IdPerfil,
Estatus=b.Estatus,
Perfil=b.Cat_Perfil.Nombre,
Sis=b.Cat_Perfil.Cat_Sistema.Nombre
};
I'm a totally newbie sorry if is a very simple question.
Thanks!!
Silverlight 3 doesn't support data binding to anonymous types.
You need to create a simple class to put your properties into.
Here is the ValueConverter technique:
namespace SilverlightApplication55
{
using System;
using System.Windows;
using System.Windows.Data;
public class NamedPropertyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || parameter == null)
{
return null;
}
var propertyName = parameter.ToString();
var property = value.GetType().GetProperty(propertyName);
if (property == null)
{
return null;
}
return property.GetValue(value, null);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
}
Then you put this in your UserControl.Resources:
<local:NamedPropertyConverter x:Key="NamedPropertyConverter"/>
And this where you want to use a named parameter - pass it in with the ConverterParameter:
<TextBlock Text="{Binding Converter={StaticResource NamedPropertyConverter}, ConverterParameter=Estatus}"/>
精彩评论