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.
Thanks for the help. I've created a feature request. I tried to look at template but this looked very complicated (did not created overriding styles for controls). The inspector tool showed me which property but I've tried to simplified workaround for now and used handling of the executed command to cancel the Add and Remove request:
if (app?.IsReadOnlyMode ?? false) { details.CommandExecuting += (sender, args) => { if (args.Command == PropertyGridCommandType.AddListEntry || args.Command == PropertyGridCommandType.RemoveListEntry) args.Cancel = true; }; }
I've adjusted your sample and removed the binding which was not working and injected my workaround and now it works.
PropertyGridReadOnlyTest_FIXED.zip
Would be much better to hide + and - commands but this takes too much effort for me. If anyone knows how to do please provide styling based on my current sample.
Hello,
It has been determined at the "+" and "-" are not dependent on whether a property is read only or has a getter. The property grid would have to be modified to accommodate this change.
Our property grid default styles are here:C:\Program Files (x86)\Infragistics\2020.1\WPF\DefaultStyles\PropertyGrid
You can import those and any changes would effectively change the the control to meet your requirements.
Adding way to do this built-in is considered to be a new product idea.
You can suggest new product ideas for future versions (or vote for existing ones) at <https://es.infragistics.com/community/ideas>. Submitting your idea will allow you to communicate directly with our product management team, track the progress of your idea at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you. Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it.
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
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.