?
Solved

WPF textbox - how to refresh associated textboxes when data changes

Posted on 2015-01-11
3
Medium Priority
?
179 Views
Last Modified: 2015-01-12
Hi
I have three textboxes. one to hold a value, one to hold a percentage and one to hold the answer to a calculation using the value and percentage.
They are all bound to the current view and work correctly on initial load of data.

They are defined like this
<TextBox x:Name="AppLicPer" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left"  Margin="5" TextWrapping="Wrap" Text="{Binding Path=CurrentlyViewingApplication.AppLicPer}"
 VerticalContentAlignment="Center" TextAlignment="Right" Width="50" />

<TextBox x:Name="AppLicValue" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Left"  Margin="5" TextWrapping="Wrap" Text="{Binding Path=CurrentlyViewingApplication.AppLicValue}"
 VerticalContentAlignment="Center" TextAlignment="Right" Width="50" />

<TextBox x:Name="AppAmountDue" Grid.Row="1" Grid.Column="4" HorizontalAlignment="Left"  Margin="5" TextWrapping="Wrap" Text="{Binding Path=CurrentlyViewingApplication.AppAmountDue}"
 VerticalContentAlignment="Center" TextAlignment="Right" Width="50" />

If I change either the value (AppLicValue) or the percentage (AppLicPer) how do I get the textbox that holds the  answer to refresh (AppAmountDue)?

In winform I would use an after_update event, recalc and write the answer to the textbox.

How can I achieve this in WPF?
Thanks
Andy
0
Comment
Question by:ieg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40543410
You need to set te Mode on your data binding:

Text="{Binding Path=CurrentlyViewingApplication.AppLicValue, Mode=TwoWay}"
0
 

Author Comment

by:ieg
ID: 40544091
Hi Eric
Thanks for the comment - I use your web site regularly, great source of info

I experimented with your idea. The Mode=TwoWay seems to control the binding of the control itself and not the content of other textboxes
My problem seems to have been caused by my use of sub properties CurrentlyViewingApplication.AppLicPer
Doing this didn't give me any way of controlling what happened when the AppLicPer value changed (only when something on CurrentlyViewingApplication changed and I didn't want this area re calculating every time something changed anywhere on the record.)

So I created a method specifically for this control binding and that allowed me to do a NotifyPropertyChanged on the AppAmountDue control

public decimal? AppLicPer
        {
            get
            {
                if (_CurrentlyViewingApplication != null)
                    return _CurrentlyViewingApplication.AppLicPer;
                else return null;
            }
            set
            {
                _CurrentlyViewingApplication.AppLicPer = value.Value;
                NotifyPropertyChanged("AppAmountDue");
            }

        }

These new MVVM concepts take some getting used to when coming from a traditional winform background
Thanks for your help
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 40544261
have you also tried to notify the change of your AppLicPer?

NotifyPropertyChanged("AppLicPer");
NotifyPropertyChanged("AppAmountDue");
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question