Welcome to the Xceed Community | Help
Community Search  
More Search Options

Conditional Binding (One way or Two way)

Sort Posts: Previous Next
  •  06-22-2009, 12:37 AM Post no. 21852

    Conditional Binding (One way or Two way)

    I am very new to WPF/Xceed and have a very basic question. :) 

    I am using DataGrid Control in my application to display a collection of objects. I want one column of my grid to be editable depending upon the type of Object. If Object is of type A, the column should be editable and if object of type B, then it should not be.

    Here is the relevant column which I am talking about.

                                         <XceedDataGrid:DataGridControl.Columns>                                        
                                            <XceedDataGrid:Column FieldName="Name"
                                                                  DisplayMemberBinding="{Binding Name, Mode=TwoWay, ValidatesOnDataErrors=True}"
                                                                  CellEditor="{StaticResource NameEditor}"
                                                                  TitleTemplate="{StaticResource EmptyTitleTemplate}">
                                            </XceedDataGrid:Column>

                                           .....
                                        </XceedDataGrid:DataGridControl.Columns>

    In the above code, as I am using Twoway Binding, the column is becoming editable for both objects and If I use 1 way binding, it becomes read-only for both. I dont know how to put this conditional binding on the column.

    Please help!!

  •  06-22-2009, 8:42 AM Post no. 21874 in reply to 21852

    Re: Conditional Binding (One way or Two way)

    You can set a column's ReadOnly property to true to prevent it from being editable. You could also use a converter (IValueConverter) on the ReadOnly property to set it to true or false depending on the desired criteria.

    Another option would be to create an implicit style that targets DataCell and that has a DataTrigger based on its FieldName in which you have a setter that sets the ReadOnly property to the desired value. 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  06-23-2009, 1:14 AM Post no. 21909 in reply to 21874

    Re: Conditional Binding (One way or Two way)

    Thanks for your quick reply.

    Before seeing your reply, I solved this by hacking the cell editor. :) Earlier my cell editor was a textbox but now I have changed my it to a 1*1 Grid which contains either a textbox or a textblock. Style on the textbox/textblock ensures that if the cell is editable then textbox is visible else textblock is. (And it seems to work well as of now)

     

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.