Custom Editor Styling

Grids for WPF Forum

Posted 12 years ago by Andrew Robinson
Version: 11.2.0554
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Avatar

Hi,

I have created a custom property editor that implements a grouped combobox based on a custom object type in our project. This works fine but the styling of the combo does not match the styling of the built-in combo that is used if, for example, a list of strings is displayed in the grid.

Can you direct me to the style to apply to the combo in the custom editor so that it visually matches your built-in editor?

Thanks

Andrew

 

P.S. I have put this in as a bug by mistake but can't see how to switch to a question. Sorry!

<DataTemplate x:Key="TagSelectionEditor_DataTemplate">
        <Grid>
            <Grid.Resources>
                <CollectionViewSource Source="{Binding StandardValues, RelativeSource={RelativeSource AncestorType={x:Type propertygrid:IPropertyDataAccessor}}}" x:Key="Tags">
                    <CollectionViewSource.GroupDescriptions>
                        <PropertyGroupDescription PropertyName="ParentName" />
                    </CollectionViewSource.GroupDescriptions>
                </CollectionViewSource>
            </Grid.Resources>
            <ribbon:ComboBox
                ItemsSource="{Binding Source={StaticResource Tags}}" 
                SelectedValue="{Binding Path=Value, RelativeSource={RelativeSource AncestorType={x:Type propertygrid:IPropertyDataAccessor}}}">
                <ComboBox.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}" FontStyle="Italic" Margin="3" />
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ComboBox.GroupStyle>
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Name}" VerticalAlignment="Center"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ribbon:ComboBox>
        </Grid>
    </DataTemplate>

[Modified 12 years ago]

Comments (2)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Andrew,

I'm assuming you are using the Aero theme, where the non-editable ComboBox looks more like a button and the editable ComboBox looks more like a TextBox. If that is the case, then our default property editors set IsEditable to true. We then set IsReadOnly to true, if the list is limited to a fixed set of standard values.

So I believe if you set these two properties on your ComboBox, then it should match up.

Also I noticed you are using a ribbon:ComboBox here, but we use the native WPF ComboBox in our templates.

[Modified 12 years ago]


Actipro Software Support

Answer - Posted 12 years ago by Andrew Robinson
Avatar

Thanks. That almost gets me there. I needed to set the BorderThickness to zero as well.

The only downside is that introduced another problem. Where the selected text for a combo item is bigger than the available space the selected text is right aligned when left would look better. I notice that someone else raised this in another thread so I have implemented the solution from there. I create a simple class inheriting from ComboBox (see below) and then override the OnDropDownClosed.

public class PropertyGridComboBox : ComboBox
    {
        public PropertyGridComboBox()
        {
            IsEditable = true;
            IsReadOnly = true;
            BorderThickness = new Thickness(0);
        }

        protected override void OnDropDownClosed(EventArgs e)
        {
            var textBox = (TextBox)this.Template.FindName("PART_EditableTextBox", this);
            textBox.ScrollToHome();
        }
    }
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.