Hi,
We have a XamPropertyGrid which we want to set to ReadOnly, based on some application-wide setting that is not related to the data that is shown in the PropertyGrid. So the data itself could still be changed, but we want to disable any controls in the applications that allows changing the data – just like with the XamPropertyGrid.
Setting IsEnabled flag of the PropertyGrid to false work fine, but this also disables the Category collapse/expand function, so if there are any collapsed categories, you can’t even view all items.
We did not found any ReadOnly option for this control which would be best match. Also tried to use editor templates but did not worked either. How we can achieve this?
We've attached example. Fallow steps:
PropertyGrid_Minimal.zip
Thanks in advance,
Tomas
Hello Tomas,
While there is no direct way to dsiable the PropertyGrid but keep the some features on or off you can write a Read Only template
Hi Michael,
Earlier provided example already has added this templates but this still does not work. Additionally, the + and - options also become enabled while this is expected to be locked in ReadOnly mode.
I tried compiling your project but it appears it's missing some files so I ran into conflicts running it. I built a new one but it appears incomplete. Please modify it and reupload it. I agree if parts of the property grid are not enabled after reenabling it I'll log this for our development team to reviewPropertyGridReadOnlyTest.zip.
Sorry for that. Your sample is almost there. Just add these lines into maintWindow.xaml.cs file to constructor:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var example = new ExampleClass(); example.Strings = new ObservableCollection<string> { "1", "2", "3" }; details.SelectedObject = example; } }
In general we won't have such a switch inside of our application since we run app either in editor mode or read only mode by changing configuration value. So all screens displayed same was in editing mode but all editing options are disabled or not visible at all.
I am still investigating this but I had to modify the sample below. I was getting some binding errors because the data templates were binding a visual element outside the property grid so I fixed that by simply using the Source directive and then removed the setter in the list collection. Now I believe it resembles what you describe where you can add more items but you cannot edit them.PropertyGridReadOnlyTest (2).zip