0

I have the following DataGridTextColumn:

  <DataGridTextColumn Header="Example" IsReadOnly="True" 
                      Binding="{Binding Ex, FallbackValue='ExampleValue'}" />

the itemSource of the dataGrid is an ObservableCollection of some class A(that has a string Ex field). I want Ex to be set to "ExampleValue", how do I do that?

Stacker
  • 29
  • 1
  • 8
  • What is ExampleValue here ? – Vivek Saurav Nov 09 '15 at 10:32
  • the Ex is a string, so in some object of class A, the Ex field = "ExampleValue" - that's what I want to happen.. – Stacker Nov 09 '15 at 10:48
  • To get value you can write `( string )( dGTest.Columns[0] as DataGridTextColumn ).Binding.FallbackValue;`. But I think it's not what you wanted. `FallbackValue` is used if Binding fails and value is unset. Why you can't set default value for `Ex` field then you initializing `ObservableCollection`? – bars222 Nov 09 '15 at 11:12
  • If ExampleValue is some property in VM you can bind it using Element Name or relative Source – Vivek Saurav Nov 09 '15 at 11:48
  • I can set default value for ex, but I have multiple data grids, and each of them work on the same class A(different observable collections but same class), and in each I want a different value to Ex, now I could just make a new classes that extends the original one, but I have many datagrids, so I thought maybe there is an easier way of doing it. – Stacker Nov 09 '15 at 12:25
  • Thanks for clarification. If bindings is `OneWay` you can try to write several `ValueConverters` for display default value, maybe it's simpler to do. – bars222 Nov 09 '15 at 12:42

0 Answers0