This project has moved and is read-only. For the latest updates, please go here.

PropertyGrid dynamically update SelectedObject binding property

Feb 3 at 11:46 AM
Edited Feb 3 at 11:51 AM
Hi,

I like to dynamically update the propertygrid on my drawing canvas when an item (CItem) on the drawing canvas is selected

I have a propertygrid in the view bound to the drawing canvas which is the viewmodel and also has a SelectedObject property:
<xctk:PropertyGrid x:Name="_propertyGrid" Margin="0"
    AutoGenerateProperties="True"
    SelectedObject="{Binding ElementName=MyDrawingCanvas, Path=SelectedObject}">
</xctk:PropertyGrid>
In my viewmodel I have an Observable<CItem> object named SelectedObject:
public Observable<CItem> SelectedObject;
And the command to update it:
private void NotifyPropertyGrid_Executed(object sender, ExecutedRoutedEventArgs e)
{
  var selectedItems = from item in SelectionService.CurrentSelection.OfType<CItem>()
    where (item.ParentID) == Guid.Empty && (item.IsSelected)
    select item;

  if (selectedItems.Count() == 1)
  {
    SelectedObject = selectedItems.SingleOrDefault();
  }
}
However, the propertygrid does not get updated.

I got the Observable<T> implementation from here:
https://www.codeproject.com/Articles/85928/Observable-Automatically-Notify-Property-Owner-Whe

Many thanks
Feb 3 at 3:48 PM
Hi,

Can you submit a testable sample so we can test this scenario ?
Thanks.

――――
Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF
Feb 3 at 9:43 PM
Hi BoucherS,

I got it working by doing this
var propGrid = GetPropertyGrid(this);
 
if (propGrid != null)
{
    var selectedItem = selectedItems.SingleOrDefault();
    propGrid.SelectedObject = selectedItem;
    propGrid.Update();
}
Thank you.