Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
When does the bound data get updated?
Message
De
20/02/2013 07:11:14
 
 
À
20/02/2013 04:15:19
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01566380
Message ID:
01566453
Vues:
40
>You could do this in XAML using a value converter:
  public class BalanceConverter : IMultiValueConverter
>  {
>    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
>    {
>      var valuesToConvert = values.Cast<string>().ToArray();
>
>      double val1;
>      double val2;
>      if (!Double.TryParse(valuesToConvert[0], out val1))
>        val1 = 0;
>      if (!Double.TryParse(valuesToConvert[1], out val2))
>        val2 = 0;
>
>      return String.Format("Balance: {0}", (val1 - val2).ToString("C"));
>    }
>
>    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
>    {
>      throw new NotImplementedException();
>    }
>  }
<Window x:Class="WpfApplication3.MainWindow"
>        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>        Title="MainWindow" Height="350" Width="525"
>        xmlns:local="clr-namespace:WpfApplication3">
>  <Window.Resources>
>    <local:BalanceConverter x:Key="balance"/>
>  </Window.Resources>
>  <StackPanel>
>    <TextBox Name="txtDepositTotal" />
>    <TextBox   Name="txtDep_Amount" VerticalAlignment="Center" />
>    <TextBox  Name="txtBalanceOutstanding" >
>      <MultiBinding Converter="{StaticResource balance}">
>        <Binding ElementName="txtDepositTotal" Path="Text"></Binding>
>        <Binding ElementName="txtDep_Amount" Path="Text"></Binding>
>      </MultiBinding>
>    </TextBox>
>  </StackPanel>
></Window>
(Converter logic could be tidier :-} )

Viv! This looks like the bees knees! Thanks very much.

Would you recommend doing something like this to display the sum of row values from a grid? (For example in this datagrid to show the DepositTotal.) Or is what I am currently doing the better way? I currently call some code in th egrid's celledit_ending to sum the crt_Amount value and store it in the DepositTotal variable which is bound to the txtDepositTotal textbox.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform