I must be missing something, but I don't know what. I have my csla dataprovider:
<csla:CslaDataProvider x:Key="ProcCodeListDataProvider" FactoryMethod="BeginGetMyList" ObjectType="SlTest.Library.MyList, SlTest.Library" IsInitialLoadEnabled="False" > </csla:CslaDataProvider>----------------------------------------------------------
On a button click, I do this (
private
void btnSubmit_Click(object sender, RoutedEventArgs e){
CslaDataProvider procCodeListProvider = this.Resources["ProcCodeListDataProvider"] as CslaDataProvider; procCodeListProvider.FactoryParameters.Clear();procCodeListProvider.FactoryParameters.Add(
this.DataContext as CodeListCrit);procCodeListProvider.Refresh();
}
----------------------------------------------------------
Everything appears to be working properly, I can even break in the Server DataPortal_Fetch method to make sure my BO is actually being "Fetched". However, my DataGrid is not populated or refreshed from the XAML binding(below)
<
data:DataGrid x:Name="grdProcCodeList" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" ItemsSource="{Binding Source={StaticResource ProcCodesListDataSource}, Path=Data}"> </data:DataGrid>----------------------------------------------------------
I'm new to XAML and this concept of databinding is quite awkward to me, because I don't know how to debug this kind of thing since it's totally handled by XAML. What am I missing??
On thing has certainly helped me troubleshoot. Let this be a lesson to any other Silverlight newbs:
I hadn't yet subscribed to the CslaDataProvider DataChanged event like so:
private
void CslaDataProvider_DataChanged(object sender, System.EventArgs e){
CslaDataProvider provider = (CslaDataProvider)(this.Resources["MyCslaDataProvider"]); if (provider.Error != null)System.Windows.Browser.
HtmlPage.Window.Alert(provider.Error.Message);}
Once the framework gets done with the async call for the BO fired from provider.Refresh() in the button click event is when it actually gets data in the provider.Data property (because of how Csla.Silverlight works with the wcf).
Now... I must figure out why I'm getting a "A parameterless constructor was not found for the object." I thought I took care of this with my SILVERLIGHT comilation symbols. Must the constructor on the Server need to be public as well for Silverlight?? or is it something else.
decius:procCodeListProvider.FactoryParameters.Add(
this.DataContext as CodeListCrit);
Maybe I'm missing something but it seems odd to me you'd be passing the data context of the control as the factory criteria.
You want to make sure any custom criteria classes have public parameterless constructors.
One way to debug binding is to include a value converter that doesn't do anything but give you a place to break.
/// <summary>
/// This class exists to aid debugging. By attaching this converter to a binding, you can /// set a break point as the object is bound and inspect it. /// </summary> public class DebugConverter : IValueConverter{
#region
IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){
Debug.WriteLine(value.ToString()); return value;}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){
Debug.WriteLine(value.ToString()); return value;}
#endregion
}
Text
="{Binding Path=ExternalId, Mode=TwoWay, Converter={StaticResource DebugConverter}}"
esaulsberry:Maybe I'm missing something but it seems odd to me you'd be passing the data context of the control as the factory criteria.
I'm a newb to Silverlight and XAML. This seemed to make sense to me, but I don't doubt that it could be odd. In the past with Csla, I've always made my own public criteria classes extended from BusinessBase to use as the factory method's parameters. That way I can bind that one class to the UI and perform validation on it from Business base etc, which has made for easy maintenance. So here, that's what I'm trying to do (I set the datacontext of the control as the criteria, then fetch the data with it and bind that result to the DataGrid). Is there a better (or more conventional) way to do this in Silverlight/XAML?? I'm so used to working with BindingSources that I'm really out of my element now.
That debug converter trick will be extremely handy! Thanks so much for that tip
A couple of things might help:
My CslaDataProviders are usually set to not load automatically (IsInitialLoadEnabled="False"). In code I load criteria parameters. For example, this code is called when the form is loaded.
_siteListProvider.FactoryParameters.Clear();
_siteListProvider.FactoryParameters.Add(
In my case, SingleCriteria frequently doesn't help for me. I usually have to pass a client ID plus some other value. I wrote a generic criteria class to support this. The corresponding criteria class looks like this:
/// <summary>[
Serializable()]private T _value;
public T Value { get { return _value; } set { _value = value; } }
/// <summary>
/// Silverlight likes a empty public constructor.
/// </summary>
}
Here is the business class, in this case a name value list.
[
Serializable()]#region
Factory & Constructors#if
SILVERLIGHT#endregion
#region
Data Portal#if
!SILVERLIGHTRaiseListChangedEvents = false;
IsReadOnly = false;
this.Add(new NameValueListBase<int, string>.NameValuePair(0, noSelectionLabel));
foreach (var p in parents)IsReadOnly =
true;
Copyright (c) Marimer LLC