I followed the sample here ProGuide Custom settings · Esri/arcgis-pro-sdk Wiki · GitHub and have added my own add-in settings to the backstage. I've binded several properties to the UI and it works great. I have a textbox where the user can browse to a folder where our company's data exists. If the user inputs an invalid folder I wanted to change the backcolor of the textbox and set the OK button to disabled until the input is fixed. A similar thing is done with the Layout options.
Ive looked in the community samples and looked at the Pro SDK and cant find anything. Where would I add my validation logic to mimic the existing Layout options?
I have attached bundle of ProjectSettingsView mvvm code of BackStage_PropertyPage sample from Esri ArcGIS Pro samples. It works
Hi Abel,
This is the WPF stuff. Look here:
https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/how-to-implement-binding-validation
Yes Im aware of the validation binding. Thank You. What I am asking is how we tap into the Pro Settings OK button to disable it when something is not valid.
You can disable OK button by setting Page IsValid property, like this:
base.IsValid = false;
Ok I am able to bind my validation rules to the textbox. It works great! Thanks!.
But now am struggling how to get that result back to the ViewModel so I can update the IsValid of the page.
My XAML looks like this
<TextBox x:Name="txtLayerDir" TextWrapping="Wrap" VerticalAlignment="Top" Margin="10,86,36,0"> <TextBox.Text> <Binding Path="MyAppDataDir" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <ui:DataPathRule/> </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox>
In the ViewModel I can initialize to False and I can see that works:
Protected Overrides Function InitializeAsync() As Task
'setup the initial validity of the Page MyBase.IsValid = False
Return Task.FromResult(0) End Function
But how do I process updates? Just cant seem to figure that one out.
In the setter for the MyAppDataDir property in the ViewModel set base.IsValid:
<SPAN class="comment token">// for example</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">string</SPAN> MyAppDataDir <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> _myAppDataDir<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">set</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="token function">SetProperty</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">ref</SPAN> _myAppDataDir<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">value</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> MyAppDataDir<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">base</SPAN><SPAN class="punctuation token">.</SPAN>IsValid <SPAN class="operator token">=</SPAN> System<SPAN class="punctuation token">.</SPAN>IO<SPAN class="punctuation token">.</SPAN>Directory<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Exists</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">value</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Wolfgang Kaiser I had something similar but didnt work. I believe its because of the Validity rules. Since the path doesnt exist then the property is never set.
Public Property MyDataDir As String Get Return _myAppDataDir End Get Set(ByVal value As String) MyBase.IsValid = False If SetProperty(_aaAnalystAppDataDir, value, Function() MyAppDataDir) Then MyBase.IsModified = True MyBase.IsValid = True 'the property passed the validity rules Else MyBase.IsValid = False End If End Set End Property
I even changed my XAML to
<Binding Path="MyAppDataDir" UpdateSourceTrigger="PropertyChanged" ValidatesOnExceptions="True" ValidatesOnDataErrors="True" NotifyOnValidationError="True">
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.