Hello, if I were to want 3 entries that all measured the same object differently, as in "Weight, Volume, Count," what technique should I look into to allow a user to enter into any of the three, and the other 2 update? Like, if I enter a Weight, the Volume and Count adjust, or you could enter a Count which recalculates the other values. The objects are being displayed in a CollectionView with a DataTemplate.
Initially, I called methods in property setters... but it causes an infinite loop. Is Multi-Binding relevant? I didn't really get the gist of what that meant. I'd be glad to share a test project if I got a tip on which way to begin it.
Thanks!
@ScumSprocket said:
Initially, I called methods in property setters... but it causes an infinite loop.
There are various approaches, but the key thing is to break the infinite loop.
One way is to do a recursion check in your setters, so that if setter B or setter C is called from setter A, they still do their work, but if setter A calls setter B (or C) which then calls setter A again, the nested setter A will not do anything.
I haven't tested this, so forgive any typo's,
This would be the code for the Weight property. Do the equivalent for Volume and Count.
public int _weight; public bool _weightCalled; public int Weight { get => _weight; set { if ((_weight != value) && (!_weightCalled)) { _weightCalled = true; _weight = value; // Raise PropertyChanged event as normal here, using base class or Invoke Volume = CalculateVolume(); Count = CalculateCount(); _weightCalled = false; } } }
The post by @stXamDev above similarly breaks the infinite loop, although this time in the code-behind of the View, with a nice use of IsFocused breaking the loop.
if (sender is Entry entry && entry.IsFocused)
@ScumSprocket said:
Is Multi-Binding relevant?
I don't think so, but I understand why the question arises. I'd stick with having three properties.
Answers
Each entry has a text changed event , capture that and accordingly change the text of the other two entries.
View
CodeBehind
Demo

There are various approaches, but the key thing is to break the infinite loop.
One way is to do a recursion check in your setters, so that if setter B or setter C is called from setter A, they still do their work, but if setter A calls setter B (or C) which then calls setter A again, the nested setter A will not do anything.
I haven't tested this, so forgive any typo's,
This would be the code for the Weight property. Do the equivalent for Volume and Count.
The post by @stXamDev above similarly breaks the infinite loop, although this time in the code-behind of the View, with a nice use of IsFocused breaking the loop.
I don't think so, but I understand why the question arises. I'd stick with having three properties.
Thanks I have been fighting some other buggy stuff, but I can't wait to try these out!
I think I'm going for the model code, because all my entries are in DataTemplates, so code-behind doesn't know where these entries are... is there a way to let the code-behind know?
You can try to use Data Binding to achieve this.
1.Create a viewmode (e.g.
TestModel.cs
)Note:When you change the first entry's value(
Entry1Word
), you can also change the binded value of other two entries.Of course, you can also change other two binded value like this.
2.Usage sample:
Thanks! I went for altering the model because I haven't found much documentation on how DataTemplates implement events.