PropertyGrid File Browsing

Grids for WPF Forum

Posted 10 years ago by Martin
Version: 13.1.0583
Avatar

Hi, I am trying to add file browsing to one of my properties. If possible, I would prefer to set this in c# code, so the properties could be changed without touching the wpf code. I have already looked into your sample property editors and PropertyGrid Integration but couldn't find a clue.

<propgrid:PropertyGrid SelectedObject="{Binding objMyData}"/>
this.DataContext = new VMMainWindow();
    public class VMMainWindow : VmBase
    {
        private Object m_objMyData;
        public Object objMyData
        {
            get
            {
                return m_objMyData;
            }
            set
            {
                if (m_objMyData != value)
                {
                    m_objMyData = value;
                    OnPropertyChanged("objMyData");
                }
            }
        }

        public VMMainWindow()
        {
            objMyData = new MyData();
        }
    }

    public class MyData
    {
        [Category("Info")]
        [Description("Path")]
        [DisplayName("Path")]
        public string FilePath { get; set; }
    }

I don't have much experience with WPF or with actipro PropertyGrid, so an example would be nice.

Thank you in advance

Comments (3)

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

Hi Martin,

Check out this related forum thread, as it has some information on making a file picker:

https://www.actiprosoftware.com/community/thread/5019/file-browsing-support#18430

But we have also added a new QuickStart for showing dialogs that is ready for the next maintenance release.  If you would like us to send that to you, please email our support address, reference this thread, and we'll send it over to you.


Actipro Software Support

Posted 10 years ago by Martin
Avatar

Thank you for your quick response.

The quickstart project comes close to what I am trying.

Just a few questions:

1. How do I get  two different Dialogs into my View. For example: OpenFileDialog() and FolderBrowserDialog()

2. In the MainControl.xaml you tell each Property if it has a Editor:

<propgrid:PropertyGrid.PropertyEditors>

<propgrid:DialogTextBoxPropertyEditor PropertyName="Path" />

</propgrid:PropertyGrid.PropertyEditors>

And in the Codebehind of your ManControl you say what kind of dialog it should use.

Is it possible to do these things in one file? For example in the ViewModel.cs? So there is only one file I have to edit when I am adding a new property.

Thank you in advance

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

Hi Martin,

The new PropertyDialog QuickStart's OnShowPropertyDialogExecute handler receives e.Parameter, which is an IPropertyDataAccessor.  You can use that to see which property is being edited and switch up the dialog based on that.

If you wanted to make a custom PropertyEditor class, you could give it a custom ValueTemplate that uses a custom command for the button. The PropertyEditors QuickStart shows an example of a custom ValueTemplate just like this.  Search its MainControl.xaml for "TextBox with dialog (Custom)" and you'll see it.  Then if you had one custom PropertyEditor for file paths and one for folder paths (and related generic custom command handlers in the code-behind), you could just set the PropertyEditors collection in XAML only for new properties.


Actipro Software Support

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.