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).
then, when auto-generating property definitions, we specify the following DataTemplate for the Size property:
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
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