midora Posted December 20, 2012 Share Posted December 20, 2012 I'm using propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.ModelDiameterTop, PropertyNames.ModelChoice, ModelChoiceList.TruncatedPyramid, true)); to enable the property ModelDiameterTop only when the property ModelChoice has the entry TruncatedPyramid selected. This works fine. Now I would like to enable ModelDiameterTop also if ModelChoice is set to TruncatedBiPyramid. Is it possible to modify the rule so that both list entries enable the ModelDiameterTop property? Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted December 20, 2012 Share Posted December 20, 2012 There is an overload of the ReadOnlyBoundToValueRule constructor which takes an array of values. Try that. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
midora Posted December 20, 2012 Author Share Posted December 20, 2012 So I replaced the parameter ModelChoiceList.TruncatedPyramid (which worked) with new[] { ModelChoiceList.TruncatedPyramid, ModelChoiceList.TruncatedBiPyramid } but the target will not be enabled if one of them is selected. Even new[] { ModelChoiceList.TruncatedPyramid } is not working. Is the syntax correct? Quote Link to comment Share on other sites More sharing options...
midora Posted December 20, 2012 Author Share Posted December 20, 2012 OK, the following worked (missed the TValue after new): propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.ModelDiameterTop, PropertyNames.ModelChoice, new object[] {ModelChoiceList.TruncatedPyramid, ModelChoiceList.TruncatedBiPyramid}, true)); Thanks Rick. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted December 21, 2012 Share Posted December 21, 2012 Hmm. Try "ReadOnlyBoundToNameValuesRule". Here's some info about it, which you'll need to make sense of it*. It says "multiple properties" but it should work if you specify the same property multiple times but with different values (which is actually how it's used in the DDS save UI) : // This class distinguishes itself from ReadOnlyBoundToValueRule`2 in that you must specify property name/value pairs. // This allows you to bind your ReadOnly to the values from multiple properties. public sealed class ReadOnlyBoundToNameValuesRule : PropertyCollectionRule { ... // (inverse = false) -> If sourceProperty.Value equals any of the values in valuesForReadOnly, then targetProperty.ReadOnly will be set to true, else it will be set to false. // (inverse = true) -> If sourceProperty.Value equals any of the values in valuesForReadOnly, then targetProperty.ReadOnly will be set to false, else it will be set to true. public ReadOnlyBoundToNameValuesRule(object targetPropertyName, bool inverse, params TupleStruct<object, object>[] sourcePropertyNameValuePairs) { ... } } * sadly this documentation only exists in the source code Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
midora Posted December 21, 2012 Author Share Posted December 21, 2012 Maybe you missed that I got the first solution to work ;-) But I also tried your second proposal now because I may need it at some time if there is a dependency of a target from multiple different sources. So I did: propRules.Add(new ReadOnlyBoundToNameValuesRule(PropertyNames.ModelDiameterTop, true, new Pair<object, object>[] { new Pair<object, object>(PropertyNames.ModelChoice, ModelChoiceList.TruncatedPyramid), new Pair<object, object>(PropertyNames.ModelChoice, ModelChoiceList.TruncatedBiPyramid)})); I had to use the 'Pair' type so maybe you changed there something already in 4.0. It is working but not when the dialog opens first. The user has to change the source object once to get the rule working. So maybe the rule will not be evaluated after the dialog has been constructed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.