This is a migrated thread and some comments may be shown as answers.

passing data from listview

3 Answers 199 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
waqas
Top achievements
Rank 1
waqas asked on 06 Jun 2018, 01:46 PM
Todo.xaml

list tap

 
private async void ToDoTaskTap(object sender, ItemTappedEventArgs e)
        {
           
 
 
                var user = ToDoTask.SelectedItem as tblEmpTask;
                if (user != null)
                {
                    var mainViewModel = BindingContext as MainViewModel;
                    if (mainViewModel != null)
                    {
                        mainViewModel.Selected = user;
                        await Navigation.PushAsync(new ToDoDetail(mainViewModel));
                         
                    
                    }
                
 
 
    }

tblEmpTask.cs

public  class tblEmpTask
    {
 
       
        public string strTaskName { get; set; }
}

TodoDetail.xaml

<telerikInput:RadDataForm x:Name="dataForm">
       <telerikInput:RadDataForm.Source>
           <local1:MainViewModel />
       </telerikInput:RadDataForm.Source>

 

   </telerikInput:RadDataForm>

MainViewModel.cs

public class MainViewModel : INotifyPropertyChanged
    {
 public tblEmpTask Selected
        {
            get { return _Selected; }
            set
            {
                _Selected = value;
                OnPropertChanged();
            }
        }
 
        [DisplayOptions(Header = "Name")]
        public string Name
        {
 
            get { return this.Selected.strTaskName; }
            set
            {
                if (value != this.Selected.strTaskName)
                {
                    this.Selected.strTaskName = value;
                    OnPropertChanged();
                }
            }
        }
}

I need to pass data to from listview to  tododetail page where i have telerik dataform, but i am not able to do it anyone can help me with that

 

 

 

3 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 07 Jun 2018, 10:24 PM
Hi Waqas,

If you must share the same view model instance for multiple pages (not recommended) then just set the DataForm source the view model property.

When you do this, you're creating a brand new instance of MainViewModel

<telerikInput:RadDataForm x:Name="dataForm">
    <telerikInput:RadDataForm.Source>
        <local1:MainViewModel />
    </telerikInput:RadDataForm.Source>
</telerikInput:RadDataForm>

Instead, set the binding context of the details page to the shared instance of MaionViewModel

var mainViewModel = BindingContext as MainViewModel;
if (mainViewModel != null)
{
    mainViewModel.Selected = user;
 
    var page = new ToDoDetailPage();
    page.BindingContext = mainViewModel;
 
    await Navigation.PushAsync(page);
}


Then, if you bind the Source property to the VM's Selected property, it will use the value set in the previous page

<telerikInput:RadDataForm x:Name="dataForm" Source="{Binding Selected}"></telerikInput:RadDataForm>

I do recommend that if you want to use MVVM, have a DetailsViewModel that has its own SelectedUser property. That way you have separate view models for different pages (or create new instances of a similar view model).


Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
waqas
Top achievements
Rank 1
answered on 08 Jun 2018, 05:50 AM

ok thanks i got it, now i have another question how i can use isvisible or isenabled for controls? like for editor if i want to hide based on any text how would i do that? this is my code for register controls

dataForm.RegisterEditor(nameof(mainViewModel.TaskName), EditorType.TextEditor);
          dataForm.RegisterEditor(nameof(mainViewModel.TaskDetail), EditorType.TextEditor);
          dataForm.RegisterEditor(nameof(mainViewModel.difficulty), EditorType.IntegerEditor);
          dataForm.RegisterEditor(nameof(mainViewModel.Reminder), EditorType.IntegerEditor);
          dataForm.RegisterEditor(nameof(mainViewModel.DateStart), EditorType.DateEditor);
          dataForm.RegisterEditor(nameof(mainViewModel.DateEnd), EditorType.DateEditor);
          dataForm.RegisterEditor(nameof(mainViewModel.Percentage), EditorType.IntegerEditor);
          dataForm.RegisterEditor(nameof(mainViewModel.AssigntTo), EditorType.TextEditor);

 

if i want to hide 1st editor which is task name how can i do that?

0
Lance | Manager Technical Support
Telerik team
answered on 08 Jun 2018, 12:21 PM
Hello Waqas,

Most of the editor functionality is set using annotations on the data model's properties. To not show an editor for a specific property, you use the [Ignore] attribute, read about all the attributes here: IgnoreAttribute.



I recommend taking a quick read through all the doc pages for the control before starting development, that way you'll know where you can find examples if you encounter any issues. You can of course always ask us, but the doc lookup would get you up and running much faster than awaiting a reply here.

Also, take a look at all the examples we've created. You can find them in the UI for Xamarin installation folder: C:\Program Files (x86)\Progress\Telerik UI for Xamarin R2 2018\Examples\Forms.   When you open the solution, drill down into the Examples folder to find the exact control and it's demos.

Here's a screenshot to guide you:




Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataForm
Asked by
waqas
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
waqas
Top achievements
Rank 1
Share this question
or