This is a migrated thread and some comments may be shown as answers.

Accessing non-browsable properties when using property sets

7 Answers 134 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Iron
Iron
David asked on 01 Nov 2013, 05:59 PM
Hi there,

We're moving from a single-selection model to a multi-selection model.  Using property sets with PropertySetMode of Intersection mostly works well for us, but I'm not sure how to change the following case.

The important points are:
- the business object exposes, for instance, Width and Height.
- we use a small wrapper class for each type of business object we have in the property grid.
- we'd like these two properties to appear together in the same line of the property grid as Size (see attached image).
- we want to have a more complicated view of the properties.  In this case, we want to have a little check box indicating whether the aspect ratio of Width/Height should be maintained.  We specify the DataTemplate for this view with the auto-generating-property process; however, parts of the DataTemplate no long have the correct binding.  We previously bound some parts of these DataTemplates to properties marked Browsable[false] -- these properties were so marked to prevent them from showing up as properties in the PropertyGrid but to have them available for binding in the DataTemplates we specify in the auto-generation process.  However, they don't show up in CurrentPropertySet.


here's some example pseudo-code.  PropertyChanged implementation elided.  As an aside, the main purpose of the business-object wrapper for the property grid is to capture and memento-ize property-grid changes for undo/redo (i show that here only to show why we will continue to have a wrapper).

public class BusinessObject : INotifyPropertyChanged
{
   public double Width { get; set; }
   public double Height { get; set; }
}

public class PropertyGridWrapper_for_BusinessObject : INotifyPropertyChanged
{
private BusinessObject m_BusinessObject = ...;
private Size m_Size = ...;
       
[Browsable(false)]
public double Width
{
get { return m_BusinessObject.Width; }
set
{
if (m_BusinessObject.Width != value)
{
if (PreserveAspect)
// change Height, as well
else
// change Width
}
}
}
 
[Browsable(false)]
public double Height { ... similar to Width ... }
 
public Size Size { get { return m_Size; } }
 
[Browsable(false)]
public bool PreserveAspect { get; set; }
}

then, when auto-generating property definitions, we specify the following DataTemplate for the Size property:

<DataTemplate x:Key="BusinessObjectSizePropertyGridTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Height:  " />
<TextBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding Height}" />
<TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Width:  " />
<TextBox Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Text="{Binding Width}" />
<Grid Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" Margin="4">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" FontFamily="Arial" Text="┐" VerticalAlignment="Bottom" Margin="0,0,0,5" />
<CheckBox Grid.Row="1" VerticalAlignment="Center" IsChecked="{Binding PreserveAspect}" />
<TextBlock Grid.Row="2" FontFamily="Arial" Text="┘" VerticalAlignment="Top" Margin="0,5,0,0" />
</Grid>
</Grid>
</DataTemplate>

using CurrentPropertySet as part of the bindings in this template doesn't work.  The bound Text property ends up being null when bound as, e.g., "CurrentPropertySet[Height]".  Do I infer correctly that the property-sets mechanism generates a dynamic object with only the browsable properties?

So, given the above example, how can we structure things to look like the image while using property sets, please?

Edit:  formatted code area

7 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
Iron
Iron
answered on 04 Nov 2013, 04:08 PM
Here is another, comparable example:

When we wish to show a combo box in the property grid, we maintain a list of possibilities in the wrapper-for-property-grid class.  In this case, instead of structuring the browsable/non-browsable properties to change the view (in the previous example, the Size property is there so that width and height appear together in the property grid), we're providing an additional piece of information for the property grid's view.

public class BusinessObject : INotifyPropertyChanged
{
   public uint SomeNumber { get; set; }
}


public class PropertyGridWrapper_for_BusinessObject : INotifyPropertyChanged
{
  private BusinessObject m_BusinessObject = ...;
        
  public uint SomeNumber
  {
    get { return m_BusinessObject.SomeNumber; }
    set
    {
      if (m_BusinessObject.SomeNumber!= value)
      {
        ...
      }
    }
  }
  
  [Browsable(false)]
  public ObservableCollection<uint> PossibleNumbers
  { get { ...} }
   
}


<DataTemplate x:Key="SomeNumberTemplate">
    <ComboBox SelectedValue="{Binding SomeNumber}"
            ItemsSource="{Binding PossibleNumbers}" />
</DataTemplate>


0
Ivan Ivanov
Telerik team
answered on 06 Nov 2013, 05:36 PM
Hello,

 I will try to prepare a sample project that meets your requirements. However, I will need a little bit more time. I will contact you as soon as I am ready with the demo.

Regards,
Ivan Ivanov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
David
Top achievements
Rank 1
Iron
Iron
answered on 06 Nov 2013, 05:53 PM
Thank you.  I look forward to the example.

If i may, I'd like to add the following:  We seem to lose our property Category specifications when using property sets.

Amending the previous example like so:

public class PropertyGridWrapper_for_BusinessObject : INotifyPropertyChanged
{  
  ...
  
  [Category("Layout")]
  public Size Size { ... }
}

We don't see a Layout category show up in the resulting property grid.  Can we still have properties grouped into categories when using property sets, please?
0
Accepted
Ivan Ivanov
Telerik team
answered on 11 Nov 2013, 05:30 PM
Hi,

Basically, we utilize an internal DynamicObject implementation behind the PropertySets feature. However, DynamicObject has quite a limited attribute support. Initially, I was thinking of preparing some custom workaround for the Browsable attribute, but it seems that it will be better to implement an internal general solution for DataAnnotations attributes. We will consider it for the incoming service pack of Q3.

Regards,
Ivan Ivanov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
David
Top achievements
Rank 1
Iron
Iron
answered on 12 Nov 2013, 03:41 PM
Okay, thanks for the update!  We will look for support for enhanced property-set functionality in the future!
0
David
Top achievements
Rank 1
Iron
Iron
answered on 22 Nov 2013, 11:25 PM
hi ivan,

are you able to tell me if the additional attribute support in property sets will make it into the 2013 Q3 service pack, please?

based on the past release history, it looks like the service packs hit about 6 weeks after the quarterly release.  i'm sure you can't give a specific date, but is that a reasonable expectation for when i might go looking for a service pack?

thanks,

-david
0
Ivan Ivanov
Telerik team
answered on 25 Nov 2013, 02:39 PM
Hi,

Service Pack should be release in a couple of weeks. We will do our best to include this changeset before the code-freeze. I will keep you in touch.

Regards,
Ivan Ivanov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
PropertyGrid
Asked by
David
Top achievements
Rank 1
Iron
Iron
Answers by
David
Top achievements
Rank 1
Iron
Iron
Ivan Ivanov
Telerik team
Share this question
or