Child NVL combobox control not generated from DataSources in VS2010

Child NVL combobox control not generated from DataSources in VS2010

Old forum URL: forums.lhotka.net/forums/t/9898.aspx


Mr X posted on Thursday, December 23, 2010

Hi all,

I am experiencing behaviours which I hope you will be able to explain to me. This should be very simple but I can't get it to work properly.  What am I missing? I am using VS2010, CLSA 4.0.1, Silverlight 4 and bxf. 

I created a root user object which contains a child NameValueList property. 

 

private static PropertyInfo<NVLSecurityProfile> RoleListProperty = RegisterProperty<NVLSecurityProfile>(c => c.RoleList);


public NVLSecurityProfile RoleList

{
get { return GetProperty(RoleListProperty); }
private set { LoadProperty(RoleListProperty, value); }

 }

 This property is loaded on the Fetch method of the root user object.  This was implemented based on the UoW examples from the CSLA 3.8 core video series.

//Load NVL

LoadProperty(RoleListProperty, Business.NVLSecurityProfile.GetNVLSecurityProfile(criteria.Language));

 

So far so good.  I put break points and I know the list is loaded with values. At this point, my objects are working fine (I think).  Then, I created a ViewModel class for my root object (user).

 

namespace ViewModels

{

public class UserViewModel : ViewModel<Business.EditUser>

{

#region "Constructors"


public UserViewModel()
{
Shell.Instance.ShowStatus(new Status { Text = "Creating User", IsBusy = true });
BeginRefresh("NewEditUser", App.Language);

}

#endregion


 (omitted to post the standard Verb and Event Handlers sections)

 Again, so far so good.  I then went ahead through VS2010 and added a new Object Datasource from my view models.  So I ended up with a object structure that looks like this. (See attachment)

 I obtain the complete object graph:  ViewModel Properties, the Model and its properties (including the child RoleList NVL).  When I drag the Model on the view, two things happen (or I better say do NOT happen):

1 . The control for the Rolelist is not added to the view when dragging and dropping the Model from the Data Sources pane.  Only the controls for the properties such as UserName, LastUpdated... are automatically generated on the view.

2. I expected the VS2010 to automatically create 2 CollectionViewSources: One for the ViewModel and one for the Model (referencing the ViewModelviewSource) .  I only obtain the CollectionViewSource for the ViewModel.

 

<

 

 

UserControl.Resources>

 <my2:NotConverter x:Key="NotConverter" />

 

 

 

 

<my3:VisibilityConverter x:Key="VisibilityConverter" />

 

 

 

 

<CollectionViewSource x:Key="userViewModelViewSource" d:DesignSource="{d:DesignInstance my:UserViewModel, CreateList=True}" />

 

 

 

 

</UserControl.Resources>

 

 

 

I have been trying to solve this for the last couple of days. I do not think this is an issue with VS2010 because this feature has been around for a while. I suspect the problem comes from having child list in my Model.  Any help would be greatly appreciated. 

thanks,

 

RockfordLhotka replied on Thursday, December 23, 2010

I know there are some bugs in the VS10 WPF designer where it doesn't consistently create CVS objects or set up the correct datacontext. Hopefully these will be fixed in VS10 SP1 - the early list of SP1 fixes does list at least one dealing with the WPF designer.

Mr X replied on Thursday, December 23, 2010

Thank you Rocky,

 I was worried that my objects implementation was the problem. So I suppose it is only a question of setting the databinding manually on my view.  Since I am not getting the ViewModelModelViewSource in the CollectionViewSource, do you believe I can simply write my own?  How do people work around this issue? 

Again, thanks for the extremely quick (and useful) reply.  Smile

 

JonnyBee replied on Thursday, December 23, 2010

Jason Zander has put together a nice overview  of the fixes in VS2010 SP1

http://blogs.msdn.com/b/jasonz/archive/2010/12/20/visual-studio-2010-service-pack-1-beta-feedback.aspx

Several items is related to XAML Designer.

 

RockfordLhotka replied on Thursday, December 23, 2010

Yes, you can write your own XAML - there's absolutely nothing special about the XAML created by the designer.

Mr X replied on Tuesday, January 18, 2011

Hi Rocky,

Thought you might be interested in this error message for future reference.  I have a root object that contains a child NVL.  When I drag my datasource onto the Silverlight grid, I get an indication that my datasource is not working properly.  I removed my NVL from the root object and was then able to drag and drop the root's object MODEL from my DataSource object (of course, I am also using MVVM). 

Using CSLA 4.0.1, Silverlight 4, MVVM and VS2010

This is the error on my xaml page:

<CollectionViewSource x:Key="EditUserViewModelViewSource" d:DesignSource="{d:DesignInstance my:EditUserViewModel, CreateList=True}" />

 The warning I get is the following:

The given key was not present in the dictionary. (Csla.NameValueListBase`2+NameValuePair[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]) C:\CSLA\CSLA Projects\CSLA 4.0.1 Projects\ARDAppMaintenance\ARDAppMaintenance.SL\Views\EditUser.xaml 18 83 ARDAppMaintenance.SL

 

My NVL object is divided into the client/server portions as such:

NVLMission.cs --> 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Csla;

using Csla.Serialization;

 

 

namespace Business

{

    [Serializable]

    public partial class NVLMission : NameValueListBase<int, string>

    {

 

    }

}

 NVLMission.Client.cs -->

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

using Csla;

using Csla.Serialization;

 

namespace Business

{

    public partial class NVLMission

    {

 

        #region Factory Methods

 

        private static NVLMission _list;

 

        public static void InvalidateCache()

        {

            _list = null;

        }

 

 

public static void GetNVLMission(int pLanguage, EventHandler<DataPortalResult<NVLMission>> callback)

        {

            if (_list == null)

            {

                var dp = new DataPortal<NVLMission>();

                dp.FetchCompleted += (o, e) =>

                {

                    if (e.Error == null)

                    {

                        //Do work here if necessary when fetch is complete

                    }

                    callback(o, e);

                };

                dp.BeginFetch(new SingleCriteria<NVLMission, int>(pLanguage));

            }

            else

            {

callback(null, new DataPortalResult<NVLMission>(_list, null, null));

            }

        }

 

        #endregion

 

        #region Data Access

 

        #endregion

 

    }

}

 

 

 NVLMission.Server.cs -->

using System;

using System.Collections.Generic;

using System.Security;

using System.Text;

using System.Data.SqlClient;

 

using Csla.Data;

using Csla;

 

namespace Business

{

    public partial class NVLMission

    {

 

        #region Factory Methods

 

        private static NVLMission _list;

 

        public static NVLMission GetNVLMission(int pLanguage)

        {

            if (_list == null)

_list = DataPortal.Fetch<NVLMission>(new SingleCriteria<NVLMission, int>(pLanguage));

            return _list;

        }

 

 

        public static void InvalidateCache()

        {

            _list = null;

        }

 

 

        #endregion

 

        #region Data Access

 

        private void DataPortal_Fetch(SingleCriteria<NVLMission, int> criteria)

        {

            RaiseListChangedEvents = false;

            IsReadOnly = false;

 

            //// TODO: load values

using (var ctx = ConnectionManager<SqlConnection>.GetManager("MyConnection"))

            {

                using (var cm = ctx.Connection.CreateCommand())

                {

                    cm.CommandType = System.Data.CommandType.StoredProcedure;

                    cm.CommandText = "MyStoredProcedure_Fetch";

                    cm.Parameters.AddWithValue("@ListName", "LISTNAME");

                    cm.Parameters.AddWithValue("@Language", criteria.Value);

 

                    using (var dr = new SafeDataReader(cm.ExecuteReader()))

                    {

                        while (dr.Read())

                        {

 

Add(new NameValueListBase<int, string>.NameValuePair(dr.GetInt32("Key"), dr.GetString("Value")));

 

                        }

                    }

                }

            }

 

            IsReadOnly = true;

            RaiseListChangedEvents = true;

        }

 

        #endregion

 

    }

}

 

 

 

Copyright (c) Marimer LLC