1

I have two text boxes Quantity and PricePerItem and a TextBlock named as TotalTb. What i want is multiply Quantity with PricePerItem and reflect result in TextBlock using CalcBinding.
Will i've to create respective properties at backend ? or Apply INotifyPropertyChanged for simple calculations like this ?
Not using MVVM. What's the simplest way to achieve this ?

<TextBox x:Name="Quantity"/>
<TextBox x:Name="PricePerItem"/>
<TextBlock x:Name="TotalTb"/>
ASh
  • 34,632
  • 9
  • 60
  • 82
Hammas
  • 29
  • 1
  • 7
  • 1) winforms-way: subscribe to `TextChanged` event of input fields, calculate and set new value for result field 2) correct way: bind everything, in input field property setters rise notification for getter-only property which return result of calculation. – Sinatr Aug 30 '19 at 07:21
  • @Sinatr i already that know that way. Even in WPF it's same but i don't want that. I want calculations in binding ... – Hammas Aug 30 '19 at 07:30
  • *"I want calculations in binding"* - what stops you? You found a library and there are examples. Can you rather show your attempt? – Sinatr Aug 30 '19 at 07:48
  • @Sinatr sir i have no idea how there examples are even working . There is text="{Cal:Binding A+B+C"} now from where A B and C came ? i literally have now idea .. – Hammas Aug 30 '19 at 07:55
  • "Will i've to create respective properties at backend ? or Apply INotifyPropertyChanged for simple calculations like this ?" and "Not using MVVM" and "the simplest way to achieve this" contradict each other – ASh Aug 30 '19 at 08:28
  • `"{Cal:Binding A+B+C}"` - here you have to [map in xaml namespace](https://stackoverflow.com/q/630468/1997232) `Cal`, it's custom class `CalcBinding.Binding` (or something), where `"A+B+C"` its constructor parameter. Those are probably just property names combined into expression. So yes, you have to define properties and start using normal bindings first. Yes, you rise notifications for those properties when they change (typically in setters). Don't be scared of MVVM, you have to set `DataContext` for binding to work and MVVM is simply all about organizing that. – Sinatr Aug 30 '19 at 08:52
  • @Sinatr Sir i do know about namespaces. And what is CalcBinding or Calc or just C.Binding . What i am not understanding is A+B+C. Please forvive me but i am not pro and just trying to understand. If i've to work with backend properties and INotify and set some Value for third box from backed (obviously there i can also do some calculation and assign value ) then what this library is doing ? – Hammas Aug 30 '19 at 10:15
  • @ASh sir i know maybe my statements are contradicting but i still believe there must be some simple and easier way for noobs like me. And i do understand how to handle this from back end but i am just thinking this way i can also just do calculations from backend and assign ..but then where is ease these libs (particularly this) is providing ? – Hammas Aug 30 '19 at 10:17
  • @Hammas, contradicting requirements make any task impossible, no solution exists – ASh Aug 30 '19 at 10:22
  • @ASh there is always a solution . Ill find no problem thanks :) – Hammas Aug 30 '19 at 15:30
  • https://stackoverflow.com/questions/1734960/which-are-practically-unsolvable-problems-in-programming-world, [List of unsolved problems in computer science](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_computer_science). the presented case is different, but still – ASh Aug 30 '19 at 15:36
  • @Hammas cannot use [calcbinding](https://github.com/Alex141/CalcBinding/issues/40) for multiple 'ElementName' properties. Have a look at: https://stackoverflow.com/questions/15661493/elegant-solution-for-readonly-values/15663083#15663083 – mcalex Aug 07 '20 at 03:26

0 Answers0