Path binding support?

Grids for WPF Forum

Posted 11 years ago by Derek Smithson - Software Developer, Vista Systems, Corp.
Avatar
It doesn't look like the PropertyGrid's SelectedObject can be bound to an object using a path expression; is this intentional or is the way I'm binding fundamentally incorrect? This is the same binding syntax I was using previously with the Mindscape grid previously:
<propGrid:PropertyGrid SelectedObject="{Binding Source={StaticResource appState}, Path=SelectedObject}"/>
In the XAML snippet above, appState is defined in the Window resources, and is a class implementing INotifyPropertyChanged (shown below).
public class ApplicationState : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private object selectedObject;
    public object SelectedObject
    {
        get { return selectedObject; }
        set
        {
            if (selectedObject != value)
            {
                selectedObject = value;

                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("SelectedObject"));
            }
        }
    }
}

Comments (5)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Derek,

Where are you setting the SelectedObject on the ApplicationState object? The binding should work fine, but the PropertyGrid would only show properties SelectedObject on the ApplicationState is set.

If you can post the code where you declare appState and/or where you set SelectedObject, then we can take a look.

Thanks


Actipro Software Support

Posted 11 years ago by Derek Smithson - Software Developer, Vista Systems, Corp.
Avatar
Hello,

In my real application the SelectedObject gets set from a variety of controls, and so to narrow down the issue I ended up creating a small test application to focus on this issue. Basically the app has two test buttons that, when pressed, set the SelectedObject to a different value.

I've zipped up this test project and put it on our site for your reference (not sure if I can attach files to the forums?), and put a few relevant code snippets below.

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
            <Button Content="State Object 1" Click="btnClicked" >
                <Button.Tag>
                    <ThisApp:MyStateObject Name="State Button 1"/>
                </Button.Tag>
            </Button>
            <Button Content="State Object 2" Click="btnClicked">
                <Button.Tag>
                    <ThisApp:MyStateObject Name="State Button 2"/>
                </Button.Tag>
            </Button>
        </StackPanel>
        
        <propGrid:PropertyGrid SelectedObject="{Binding Source={StaticResource appState}, Path=SelectedObject}" Margin="5" Grid.Row="1"/>
    </Grid>

public class MyStateObject
{
    public string Name { get; set; }
    public string TypeName { get { return this.GetType().Name; } }
}

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }

    private void btnClicked(object sender, RoutedEventArgs e)
    {
        ApplicationState state = (ApplicationState)FindResource("appState");
        state.SelectedObject = ((Button)sender).Tag;
    }
}
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Derek,

There was a bug in the PropertyGrid, which occurs when you set the SelectedObject after the control has been loaded. We've fixed this for the next release.

As a temporary work around you could set the SelectedObjects property instead.

Thanks.


Actipro Software Support

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi, just wanted to let you know we uploaded a new v4.5 beta build (same build number as the first beta) to the same URL as before. You can uninstall the one you have, install the new build, and it should have this issue resolved.

It also adds a new QuickStart for category editors.


Actipro Software Support

Posted 11 years ago by Derek Smithson - Software Developer, Vista Systems, Corp.
Avatar
Thanks for the update. I installed the new beta, and sure enough the binding updates are working perfectly in both my test app and my main application.


Thanks again.

[Modified at 08/29/2008 07:43 PM]
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.