0

データグリッドにバインドする匿名のlinqクエリがあります。デバッグすると、データは正常に表示されますが、データグリッドに表示されません。データグリッドにバインドする前に、RIAサービスへのリクエストが完了していないと思われます。 。LoadOperation <>()Completedイベントを使用できます。しかし、それは定義されたエンティティでのみ機能するので、どうすればそれを行うことができますか?参考までに、最後の投稿は次のとおりです 。LINQクエリのnull参照例外 クエリは次のとおりです。

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

                                 };

非常に単純な質問である場合、私は完全に初心者の申し訳ありません。

ありがとう!!

4

1 に答える 1

0

Silverlight 3 は、匿名型へのデータ バインディングをサポートしていません。

プロパティを配置する単純なクラスを作成する必要があります。

ValueConverter テクニックは次のとおりです。

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;        
    }
}
}

次に、これを UserControl.Resources に入れます。

<local:NamedPropertyConverter x:Key="NamedPropertyConverter"/>

そして、これは名前付きパラメーターを使用したい場所です - ConverterParameter でそれを渡します:

<TextBlock Text="{Binding Converter={StaticResource NamedPropertyConverter}, ConverterParameter=Estatus}"/>
于 2010-03-10T15:55:33.020 に答える