passing data from listview

4 posts, 0 answers
  1. waqas
    waqas avatar
    2 posts
    Member since:
    May 2018

    Posted 06 Jun 2018 Link to this post

    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

     

     

     

  2. Lance | Technical Support Engineer, Principal
    Admin
    Lance | Technical Support Engineer, Principal avatar
    1022 posts

    Posted 07 Jun 2018 Link to this post

    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
  3. waqas
    waqas avatar
    2 posts
    Member since:
    May 2018

    Posted 08 Jun 2018 in reply to Lance | Technical Support Engineer, Principal Link to this post

    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?

  4. Lance | Technical Support Engineer, Principal
    Admin
    Lance | Technical Support Engineer, Principal avatar
    1022 posts

    Posted 08 Jun 2018 Link to this post

    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
Back to Top