Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
ComboBox as custom editor for xamPropertyGrid
posted

I have seen the example that uses a slider control for a custom editor.  Using that as a base, I tried to use a ComboBox instead of the slider.  The ComboBox shows the bound ItemsSource just fine, but I cannot get the default item set based on the existing value in the property, and when I change the item, I get the error:

A first chance exception of type 'System.NullReferenceException' occurred in InfragisticsWPF4.Controls.Editors.XamPropertyGrid.v14.2.dll
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=Value; DataItem='PropertyGridPropertyItem' (HashCode=38992001); target element is 'ComboBox' (Name=''); target property is 'SelectedItem' (type 'Object') NullReferenceException:'System.NullReferenceException: Object reference not set to an instance of an object.
at Infragistics.Controls.Editors.PropertyGridPropertyItem.OnValuePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
at MS.Internal.Data.ClrBindingWorker.UpdateValue(Object value)
at System.Windows.Data.BindingExpression.UpdateSource(Object value)'

There is a null reference in there somewhere, but not in my immediate code (the setter never even gets called, the crash happens before the data is sent form the property grid to the bound object).

Here is the XAML snippet:

 

<ig:XamPropertyGrid SelectedObject="{Binding Model}" >
   <ig:XamPropertyGrid.EditorDefinitions>
      <ig:PropertyGridEditorDefinition>
         <ig:PropertyGridEditorDefinition.TargetProperties>
            <sys:String>AAADropdownTest</sys:String>
         </ig:PropertyGridEditorDefinition.TargetProperties>
         <ig:PropertyGridEditorDefinition.EditTemplate>
            <DataTemplate>
               <ComboBox
                  ItemsSource="{Binding DataContext.MyItemList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=OneWay}"
                  DisplayMemberPath="Name"
                  SelectedItem="{Binding Path=Value, Mode=TwoWay}">
               </ComboBox>
            </DataTemplate>
         </ig:PropertyGridEditorDefinition.EditTemplate>
      </ig:PropertyGridEditorDefinition>
   </ig:XamPropertyGrid.EditorDefinitions>
</ig:XamPropertyGrid>

The databound Model property AAADropdownTest is of the same type that the MyItemList collection contains.

Do you have a working example of a ComboBox editor in a PropertyGrid? Thanks!!!

Parents Reply Children