Sign in to follow this  
xod

Indirect UI – property rules

Recommended Posts

 

I don't want to abuse for your kindness but maybe you can help me in the next problem:

//two sliders AmountX, AmountY with link checkbox = AmountZ; if the checkbox is ticked then AmountX and AmountY sliders is linked.
propRules.Add(new LinkValuesBasedOnBooleanRule<int, Int32Property>(new ValueType[] { PropertyNames.AmountX, PropertyNames.AmountY }, PropertyNames.AmountZ, false)); //found on simonbrown site

//one slider = AmountX with enable checkbox = AmountY; if the checkbox is unticked then AmountX slider is disabled.
 propRules.Add(new ReadOnlyBoundToBooleanRule(PropertyNames.AmountX, PropertyNames.AmountY, true));//also found on simonbrown site

Now, if I have a dropdown list and I want to enable a slider when an option from that dropdown list is choosed, how can I make that?

 

propRules.Add(new ReadOnlyBoundToBooleanRule(PropertyNames.AmountXOptionN, PropertyNames.AmountY, true));//does not work

 

Edited by BoltBait
Split from unrelated topic

Share this post


Link to post
Share on other sites

Your code might look like this:

        protected override PropertyCollection OnCreatePropertyCollection()
        {
            List<Property> props = new List<Property>();
            
            props.Add(StaticListChoiceProperty.CreateForEnum<AmountXOptions>(PropertyNames.AmountX, 0, false));
            props.Add(new Int32Property(PropertyNames.AmountY, 5, 0, 100));
            ...
            ...
            
            List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>();
            propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.AmountY, PropertyNames.AmountX, AmountXOptions.AmountXOptionN, true));
            
            return new PropertyCollection(props, propRules);
        }

Pay attention to the last line.

  • Upvote 1

Share this post


Link to post
Share on other sites

If I have a dropdown list with 8 options and I want to enable a slider when only 3 options (not necessarily one after another) from that dropdown list is choosed, how can I make that?

Share this post


Link to post
Share on other sites

You need to create a rule for each of those 3 options.

 

Example:

propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption2, true));
propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption5, true));
propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption7, true));

^^ When DropDown options 2, 5, or 7 are selected, the slider will be enabled.

Share this post


Link to post
Share on other sites

I tried this but only when I select the last one =7 the slider it's enabled.

Edited by xod

Share this post


Link to post
Share on other sites

Hmm, well, instead of creating rules for those 3 options, create rules for the other 5 options. Just change the boolean from true to false.
 

Example:

propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption2, false));
propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption3, false));
propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption4, false));
propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption6, false));
propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, MyDropDownOptions.MyDropDownOption7, false));

Share this post


Link to post
Share on other sites

Oh, sorry.  I got confused. :/

You can have have a single source property control multiple target properties, but not vise-versa.

 

I not sure what you could do.

Share this post


Link to post
Share on other sites

I believe the proper format is:

object[] conditions = new object[] { MyDropDownOptions.MyDropDownOption2, MyDropDownOptions.MyDropDownOption3 };

propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.MySlider, PropertyNames.MyDropDown, conditions, false));
  

 

EDIT: A more complete explanation is here.

  • Upvote 3

Share this post


Link to post
Share on other sites

Thank you MJW.
For more complex situations like the one in the picture below I tried to create a new cond2 condition, but it does not work.

 

sjHKNdd.png

 

object[] cond1 = new object[] {Amount9Options.Amount9Option2, Amount9Options.Amount9Option5, Amount9Options.Amount9Option8};
            propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.Amount10, PropertyNames.Amount9, cond1, true));
            propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.Amount11, PropertyNames.Amount9, cond1, true));

object[] cond2 = new object[] {Amount9Options.Amount9Option3, Amount9Options.Amount9Option6};
            propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.Amount10, PropertyNames.Amount9, cond2, true))

 

Edited by xod

Share this post


Link to post
Share on other sites
58 minutes ago, xod said:

For more complex situations like the one in the picture below I tried to create a new cond2 condition, but it does not work.

 

I'm not clear what each option is supposed to do. For instance, what the difference is between Option2 and Option5, both of which are labeled "Slider X, Y". it's certainly possible to enable any combination of the sliders with the list box.

 

Assuming the labels specify which controls to enable:

object[] condX = new object[] {Amount9Options.Amount9Option2, Amount9Options.Amount9Option3, Amount9Options.Amount9Option5, Amount9Options.Amount9Option6, Amount9Options.Amount9Option8};

object[] condY = new object[] {Amount9Options.Amount9Option2, Amount9Options.Amount9Option4, Amount9Options.Amount9Option5, Amount9Options.Amount9Option7, Amount9Options.Amount9Option8};

 

You probably have something more complex in mind.

  • Upvote 1

Share this post


Link to post
Share on other sites
20 minutes ago, xod said:

It's about that kind of situation:

 

In that case, I expect the values I gave should work. Each control is independent: it only cares about the values that enable it, so there's really no additional complexity in enabling two slider controls with one list control.

 

If you were trying to enable a single control based on the values of two controls, that would be more complex -- and as far as I know, impossible.

  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this