ieg
asked on
WPF textbox - how to refresh associated textboxes when data changes
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=CurrentlyViewingAppli cation.App LicPer}"
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=CurrentlyViewingAppli cation.App LicValue}"
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=CurrentlyViewingAppli cation.App AmountDue} "
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
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"
VerticalContentAlignment="
<TextBox x:Name="AppLicValue" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Left"
VerticalContentAlignment="
<TextBox x:Name="AppAmountDue" Grid.Row="1" Grid.Column="4" HorizontalAlignment="Left"
VerticalContentAlignment="
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
ASKER
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 CurrentlyViewingApplicatio n.AppLicPe r
Doing this didn't give me any way of controlling what happened when the AppLicPer value changed (only when something on CurrentlyViewingApplicatio n 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 (_CurrentlyViewingApplicat ion != null)
return _CurrentlyViewingApplicati on.AppLicP er;
else return null;
}
set
{
_CurrentlyViewingApplicati on.AppLicP er = value.Value;
NotifyPropertyChanged("App AmountDue" );
}
}
These new MVVM concepts take some getting used to when coming from a traditional winform background
Thanks for your help
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 CurrentlyViewingApplicatio
Doing this didn't give me any way of controlling what happened when the AppLicPer value changed (only when something on CurrentlyViewingApplicatio
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 (_CurrentlyViewingApplicat
return _CurrentlyViewingApplicati
else return null;
}
set
{
_CurrentlyViewingApplicati
NotifyPropertyChanged("App
}
}
These new MVVM concepts take some getting used to when coming from a traditional winform background
Thanks for your help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Text="{Binding Path=CurrentlyViewingAppli