Jump to content

IndirectUI: StaticListChoiceProperty rule


midora
 Share

Recommended Posts

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?

 

midoras signature.gif

Link to comment
Share on other sites

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?

midoras signature.gif

Link to comment
Share on other sites

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.

midoras signature.gif

Link to comment
Share on other sites

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

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

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.

midoras signature.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...