We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SelectedCard DataContext

Thread ID:

Created:

Updated:

Platform:

Replies:

128073 Dec 30,2016 03:58 PM UTC Jan 2,2017 07:22 AM UTC UWP 1
loading
Tags: SfKanban
Jame Thomas
Asked On December 30, 2016 03:58 PM UTC

Hello,
I am working with the SFKanban control populated by LinqtoSql query.  Populating the control is not an issue, and everything works as expected; however, attempting to get the values from  SelectedCard in a drag or tapped event results in an object reference null error.  I could not find any documentation or samples on how to get these values, so I apologize ahead of time if this is covered elsewhere. Please let me know how I could go about getting these values.  Below is my code. Thanks in advance for your help!


-------------XAML-------------
 
<!-- Data Template for Card -->
<DataTemplate x:Key="CardTemplate">
       <Grid>
             <TextBlock Text="{Binding FirstName}"/>
             <TextBlock Text="{Binding LastName}"/>
        </Grid>
</DataTemplate>

<!-- Kanban -->
 <my2:SfKanban x:Name="TaskList"
                       ColumnMappingPath="Status"
                       AutoGenerateColumns="False"
                      CardTemplate="{StaticResource CardTemplate}" CardDragEnd="TaskList_CardDragEnd" >
            <my2:KanbanColumn Categories="Not Started" Title="Not Started"></my2:KanbanColumn>
            <my2:KanbanColumn Categories="In Progress" Title="In Progress"></my2:KanbanColumn>
            <my2:KanbanColumn Categories="Pending" Title="Pending"></my2:KanbanColumn>
            <my2:KanbanColumn Categories="Completed" Title="Completed"></my2:KanbanColumn>
</my2:SfKanban>

---------Code Behind----------

// LinqtoSql Query
protected override void OnNavigatedTo(NavigationEventArgs e)
{
     //Get the Active Teacher to apply to query
     int teacher = Convert.ToInt32(localSettings.Values["ActiveTeacher"]);
    
     //Query student list based on Active Teacher
     using (var db = new DatabaseContext())
     {
         var query = from t in db.Students
         where t.TeachersId == teacher
                select new Models.Students() { StudentsId = t.StudentsId, FirstName = t.FirstName, LastName = t.LastName, DOB = t.DOB, Status = t.Status };
         TaskList.ItemsSource = query.ToList();
      }
}


// Drag Event
  private async void TaskList_CardDragEnd(object sender, KanbanDragEndEventArgs e)
{
     //Cast SFKanban Datacontext to Students class      
     Models.Students student = (sender as SfKanban).DataContext as Models.Students;
     e.SelectedCard.DataContext = student;
     var selectedstudent = student.StudentsId.ToString();
  
    //Test for valid returned StudentId
     var dialog = new MessageDialog(e.SelectedCard.DataContext.ToString());
     await dialog.ShowAsync();
}


Sumathi Jayaraj [Syncfusion]
Replied On January 2, 2017 07:22 AM UTC

Hi Jame,   
   
Thanks for contacting our Syncfusion Support.   
   
By default, DataContext for all the controls is exist only if we set explicitly. Otherwise, its value is null. We can get the underlying data for the selected card, from the “Content” property. Please find the below code sample for your reference.     
   
Code sample [C#]: 
 
// Drag Event 
private async void TaskList_CardDragEnd(object sender, KanbanDragEndEventArgs e) 
{ 
    //Casting selected card's Datacontext to Students class        
    Students student = e.SelectedCard.Content as Students; 
    var selectedstudent = student.StudentsId.ToString(); 
 
    //Returned StudentId for the selected card. 
    var dialog = new MessageDialog(selectedstudent); 
    await dialog.ShowAsync(); 
} 
 
 
Regards, 
Sumathi J 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;