Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: UserControl as custom editor

$
0
0
We are trying to use a UserControl as a custom editor in the PropertyGrid. But it is displaying as a TextBox instead of the ComboBox as defined in the UserControl. The UserControl implements the ITypeEditor interface as follows where GroupName is the property that is being updated:
  #region ITypeEditor Members

  // Used to support extended tool kit property grid used in EditLabelPrinter screen.
  public FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem)
  {
      Binding binding = new Binding("GroupName");
      binding.Source = propertyItem;
      binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
      BindingOperations.SetBinding(this, GroupNameUserControl.GroupNameProperty, binding);

      return this;
  }

  #endregion
Below is the xaml declaration.
<xctk:EditorDefinition>
      <xctk:EditorDefinition.PropertiesDefinitions>
          <xctk:PropertyDefinition Name="GroupName" />
      </xctk:EditorDefinition.PropertiesDefinitions>
      <xctk:EditorDefinition.EditorTemplate>
          <DataTemplate>
              <GroupName:GroupNameUserControl GroupName="{Binding Value}" EditingType="LabelDefinition" CurrentInstance="{Binding RelativeSource={RelativeSource AncestorType={x:Type mwf:ContentScreen}}, Path=DataContext}" ControlGap="3" ToolTip="Can be used to group etchers together"/>
          </DataTemplate>
      </xctk:EditorDefinition.EditorTemplate>
  </xctk:EditorDefinition>
  1. None of the c# code, such as the constructor, is being called.
  2. When we use this UserControl elsewhere, the CurrentInstance is bound to the DataContext.
    I am not sure what to bind the CurrentInstance to in the context of a PropertyGrid.
  3. We define a string type editor later in the xaml declaration - could that be cancelling the
    UserControl editor definition - the type string editor definition is as below:
<!-- Makes all strings selected when the user tabs through the property grid -->
  <xctk:EditorDefinition TargetType="{x:Type sys:String}">
      <xctk:EditorDefinition.EditorTemplate>
          <DataTemplate>
              <xctk:WatermarkTextBox Text="{Binding Value}" SelectAllOnGotFocus="True"/>
          </DataTemplate>
      </xctk:EditorDefinition.EditorTemplate>
  </xctk:EditorDefinition>
We are using an older version of the extended tool kit, but I cannot change that.

Thanks in advance for any ideas or suggestions!

Viewing all articles
Browse latest Browse all 4964

Trending Articles