Binding other properties to row item

5 posts, 2 answers
  1. Marcel
    Marcel avatar
    41 posts
    Member since:
    Jan 2014

    Posted 04 Aug Link to this post

    Hello,

    I have a I think very simple question but I cant find any solution for it. Its about binding other properties, besides the DataMemberBinding to the current item. 

    The scenario is as follows, I have a data object which is setup as follows:

    public class EmployeeViewModel
    {
        public Employee EmployeeData { get; set; }
     
        public EmployeeViewState ViewState { get; set; }
    }
     
    public class Employee
    {
        public string Name { get; }
    }
     
    public class EmployeeViewState
    {  
        public bool ColumnNameReadOnly = true;
    }

     

    In my main viewmodel I have the following:

    public class ViewModel
    {
        public ObservableCollection<EmployeeViewModel> Employees { get; set; }
     
    }

     

    Now I want to bind my view to this collection, I have the following XAML:

    <telerik:RadGridView x:Name="grid" MinHeight="400"
                        DataContext="{Binding}"
                        ItemsSource="{Binding Employees}">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Header="Name:"
                                        DataMemberBinding="{Binding Path=EmployeeData.Name}"                                                    
                                        Width="215"
                                        IsReadOnly="{Binding Path=ViewState.ColumnNameReadOnly}"/>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

     

    The Name property of the EmployeeData object is correctly bind to the current item of the row, but the IsReadOnly property binding is looking for a ViewState object in my main viewmodel!

    How can I set the datacontext for this property the same as with the DataMemberBinding?

     

    Regards,

     

    Marcel

  2. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 05 Aug Link to this post

    Hello Marcel,

    In this particular scenario, you should use the IsReadOnlyBinding property rather than the IsReadOnly property.

    I'm attaching a sample project to demonstrate how you should use it in this case. I hope you find it helpful.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Marcel
    Marcel avatar
    41 posts
    Member since:
    Jan 2014

    Posted 05 Aug in reply to Dilyan Traykov Link to this post

    Hello Dilyan,

    Thanks this works great, but when I have other properties that I also want to bind to the particular row business object (for example the TabStopMode or IsEnabled  properties) how would I do this?

     

     

    Regards,

     

    Marcel

  5. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 05 Aug Link to this post

    Hello Marcel,

    Setting these properties on a cell/row level can be achieved by using RadPropertyGrid's CellStyleSelector and RowStyleSelector properties.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Marcel
    Marcel avatar
    41 posts
    Member since:
    Jan 2014

    Posted 10 Aug in reply to Dilyan Traykov Link to this post

    Thanks, Dilyan.

    This got me a little further.

    Regards,

    Marcel

Back to Top
UI for WPF is Visual Studio 2017 Ready