Click here to Skip to main content
11,709,844 members (48,018 online)

Silverlight / WPF

 
AnswerRe: web services Pin
Abhinav S12-May-13 18:29
mvpAbhinav S12-May-13 18:29 
GeneralRe: web services Pin
picasso212-May-13 20:21
memberpicasso212-May-13 20:21 
QuestionHow to acheive the given layout in Silverlight? Pin
New Coder1239-May-13 22:55
memberNew Coder1239-May-13 22:55 
AnswerRe: How to acheive the given layout in Silverlight? Pin
Abhinav S12-May-13 7:47
mvpAbhinav S12-May-13 7:47 
QuestionSL application does not works-nothing change Pin
picasso28-May-13 18:48
memberpicasso28-May-13 18:48 
AnswerRe: SL application does not works-nothing change Pin
Abhinav S12-May-13 7:45
mvpAbhinav S12-May-13 7:45 
QuestionBinding issues with Treeview C# WPF Pin
bartbartb2-May-13 11:41
memberbartbartb2-May-13 11:41 
AnswerRe: Binding issues with Treeview C# WPF Pin
Kenneth Haugland3-May-13 2:22
professionalKenneth Haugland3-May-13 2:22 
AnswerRe: Binding issues with Treeview C# WPF Pin
Mycroft Holmes9-May-13 12:23
professionalMycroft Holmes9-May-13 12:23 
QuestionVisualTreeHelper.HitTest / RectangleGeometry not working... Pin
SledgeHammer012-May-13 7:26
memberSledgeHammer012-May-13 7:26 
AnswerRe: VisualTreeHelper.HitTest / RectangleGeometry not working... Pin
Kenneth Haugland2-May-13 7:38
professionalKenneth Haugland2-May-13 7:38 
QuestionTab Closing Problem Pin
Kevin Marois1-May-13 20:14
memberKevin Marois1-May-13 20:14 
AnswerRe: Tab Closing Problem Pin
Amitosh Swain3-May-13 4:49
memberAmitosh Swain3-May-13 4:49 
QuestionAsynchronous Call Using MVVM Pin
jonkjon29-Apr-13 10:21
memberjonkjon29-Apr-13 10:21 
I am using this in the code behind for a xaml page and it works fine for retrieving the data for a listbox:

_______________________________________________________________

SLConnDomainContext dbContext = new SLConnDomainContext();
        private LoadOperation<Employee> loadOp;
        ObservableCollection<Employee> data = new ObservableCollection<Employee>();
 
        public Filters()
        {
            InitializeComponent();
            loadOp = this.dbContext.Load(this.dbContext.GetEmployeesQuery());
         loadOp.Completed += new EventHandler(loadOp_Completed);
 
        }
 
        void loadOp_Completed(object sender, EventArgs e)
        {
            foreach (Employee emp in loadOp.Entities)
            {
                data.Add(emp);
            }
 
            dataForm.ItemsSource = data;
 
        }

I would like to move to a MVVM approach and have created a viewmodel to retrieve the data and pass it into a view by creating an instance of my viewmodel and setting the datacontext property of my listbox. The viewmodel works fine when I am just creating some mock data and populating a list. However, due to the asynchronous nature of using a loadoperation with silverlight, the above code doesn't work with the MVVM approach for me. The data is retrieved but it appears that it is after my view has already loaded so it never appears. Below is my code:

Viewmodel:
______________________________________________________________

{
 
    public partial  class EmployeeService
    {
        private SLConnDomainContext Context = new SLConnDomainContext();
        private LoadOperation<Employee> loadOp;
        public ObservableCollection<Employee> employees = new ObservableCollection<Employee>();
        
        public EmployeeService()
        {
           
         
            loadOp = Context.Load(Context.GetEmployeesQuery(), LoadBehavior.MergeIntoCurrent, employeeCallBack, null);
             
        }
       
 

        void employeeCallBack(LoadOperation<Employee> op)
        {
            foreach (Employee emp in loadOp.Entities)
            {
                employees.Add(emp);
               
            }
            _myEmployees = employees;
	//using below to determine that data is retrieved
            MessageBox.Show("I have " + employees.Count + " employees");
        }
      
 
     
     
        public IEnumerable<Employee> GetEmployees()
       {
                  
            return employees;
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
        private ObservableCollection<Employee> _myEmployees;
        public ObservableCollection<Employee> myEmployees
        {
            get { return _myEmployees; }
            set
            {
                myEmployees = value;
                OnPropertyChanged("myEmployees");
            }
        }
 

 
        private int _EmployeeID;
        public int EmployeeID
        {
            get { return _EmployeeID; }
            set
            {
                _EmployeeID = value;
                OnPropertyChanged("EmployeeID");
            }
        }
 
        private int _VacationHours;
        public int VacationHours
        {
            get { return _VacationHours; }
            set
            {
                _VacationHours = value;
                OnPropertyChanged("VacationHours");
            }
        }
 

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
       
    }
 
}

This is set in the constructor for the view's code behind:

______________________________________________________________

public LayoutTest()
       {
           InitializeComponent();
          EmployeeService myservice = new EmployeeService();
          EmployeeList.DataContext = myservice;
 
       }

I have the databinding set correclty as it works if I use something like this in place of the above GetEmployees():
______________________________________________________________


public IEnumerable<Employee> GetEmployees()
        {
            List<Employee> employees = new List<Employee>();
            EmployeeService test = new EmployeeService();
            foreach (Employee emp in test.GetEmployees())
            { 
            employees.Add(emp);
            }
              
            Employee employee = new Employee();
            employee.EmployeeID = 1111;
            employee.VacationHours = 100;
 
            employees.Add(employee);
 
            employee = new Employee();
            employee.EmployeeID = 1112;
            employee.VacationHours = 62;
            employees.Add(employee);
 
            employee = new Employee();
            employee.EmployeeID = 1113;
            employee.VacationHours = 132;
            employees.Add(employee);
            return employees;
        }

I am sure this is due to the asynchronous call but I don't know how to fix it. Thanks for any help.
AnswerRe: Asynchronous Call Using MVVM Pin
SledgeHammer0129-Apr-13 10:32
memberSledgeHammer0129-Apr-13 10:32 
GeneralRe: Asynchronous Call Using MVVM Pin
jonkjon29-Apr-13 10:48
memberjonkjon29-Apr-13 10:48 
Questionwin32 window as c# wpf control Pin
mkusnjer29-Apr-13 8:58
membermkusnjer29-Apr-13 8:58 
AnswerRe: win32 window as c# wpf control Pin
SledgeHammer0129-Apr-13 9:28
memberSledgeHammer0129-Apr-13 9:28 
GeneralRe: win32 window as c# wpf control Pin
mkusnjer30-Apr-13 5:19
membermkusnjer30-Apr-13 5:19 
GeneralRe: win32 window as c# wpf control Pin
SledgeHammer0130-Apr-13 10:58
memberSledgeHammer0130-Apr-13 10:58 
GeneralRe: win32 window as c# wpf control Pin
mkusnjer1-May-13 8:31
membermkusnjer1-May-13 8:31 
GeneralRe: win32 window as c# wpf control Pin
SledgeHammer011-May-13 10:46
memberSledgeHammer011-May-13 10:46 
GeneralRe: win32 window as c# wpf control Pin
mkusnjer1-May-13 12:11
membermkusnjer1-May-13 12:11 
GeneralRe: win32 window as c# wpf control Pin
SledgeHammer011-May-13 12:20
memberSledgeHammer011-May-13 12:20 
GeneralRe: win32 window as c# wpf control Pin
mkusnjer1-May-13 12:39
membermkusnjer1-May-13 12:39 
GeneralRe: win32 window as c# wpf control Pin
SledgeHammer011-May-13 13:00
memberSledgeHammer011-May-13 13:00 
GeneralRe: win32 window as c# wpf control Pin
mkusnjer1-May-13 13:24
membermkusnjer1-May-13 13:24 
AnswerRe: win32 window as c# wpf control Pin
Amitosh Swain3-May-13 4:33
memberAmitosh Swain3-May-13 4:33 
QuestionDynamically create radiobuttons under the group header that can span to N - number of groups Pin
Rajesh Sajjanar27-Apr-13 10:29
memberRajesh Sajjanar27-Apr-13 10:29 
AnswerRe: Dynamically create radiobuttons under the group header that can span to N - number of groups Pin
Kenneth Haugland27-Apr-13 12:32
professionalKenneth Haugland27-Apr-13 12:32 
AnswerRe: Dynamically create radiobuttons under the group header that can span to N - number of groups Pin
Mycroft Holmes27-Apr-13 13:06
professionalMycroft Holmes27-Apr-13 13:06 
QuestionIdeaBlade vs OData Pin
Super Lloyd25-Apr-13 18:36
memberSuper Lloyd25-Apr-13 18:36 
QuestionWPF Login in MVVM Issue Pin
KishoreUHG21-Apr-13 23:44
memberKishoreUHG21-Apr-13 23:44 
AnswerRe: WPF Login in MVVM Issue Pin
Mycroft Holmes21-Apr-13 23:50
professionalMycroft Holmes21-Apr-13 23:50 
GeneralRe: WPF Login in MVVM Issue Pin
KishoreUHG21-Apr-13 23:52
memberKishoreUHG21-Apr-13 23:52 
GeneralRe: WPF Login in MVVM Issue Pin
Mycroft Holmes21-Apr-13 23:59
professionalMycroft Holmes21-Apr-13 23:59 
GeneralRe: WPF Login in MVVM Issue Pin
KishoreUHG22-Apr-13 0:08
memberKishoreUHG22-Apr-13 0:08 
AnswerRe: WPF Login in MVVM Issue Pin
Wayne Gaylard22-Apr-13 1:44
mentorWayne Gaylard22-Apr-13 1:44 
AnswerRe: WPF Login in MVVM Issue Pin
KishoreUHG22-Apr-13 2:52
memberKishoreUHG22-Apr-13 2:52 
GeneralRe: WPF Login in MVVM Issue Pin
Mycroft Holmes22-Apr-13 12:59
professionalMycroft Holmes22-Apr-13 12:59 
QuestionWPF Simular to tree view Pin
Saksida Bojan21-Apr-13 9:52
memberSaksida Bojan21-Apr-13 9:52 
AnswerRe: WPF Simular to tree view Pin
Richard MacCutchan21-Apr-13 22:39
mvpRichard MacCutchan21-Apr-13 22:39 
GeneralRe: WPF Simular to tree view Pin
Saksida Bojan2-May-13 7:41
memberSaksida Bojan2-May-13 7:41 
QuestionWPF User Controls - Interacting With Other Controls Pin
Kevin Marois19-Apr-13 5:10
memberKevin Marois19-Apr-13 5:10 
AnswerRe: WPF User Controls - Interacting With Other Controls Pin
Mycroft Holmes19-Apr-13 13:19
professionalMycroft Holmes19-Apr-13 13:19 
GeneralRe: WPF User Controls - Interacting With Other Controls Pin
Kevin Marois19-Apr-13 13:21
memberKevin Marois19-Apr-13 13:21 
GeneralRe: WPF User Controls - Interacting With Other Controls Pin
Mycroft Holmes19-Apr-13 13:26
professionalMycroft Holmes19-Apr-13 13:26 
GeneralRe: WPF User Controls - Interacting With Other Controls Pin
_Maxxx_7-May-13 20:09
member_Maxxx_7-May-13 20:09 
GeneralRe: WPF User Controls - Interacting With Other Controls Pin
SledgeHammer0124-Apr-13 8:48
memberSledgeHammer0124-Apr-13 8:48 
GeneralRe: WPF User Controls - Interacting With Other Controls Pin
Mycroft Holmes24-Apr-13 12:25
professionalMycroft Holmes24-Apr-13 12:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 27 Aug 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid