Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6369161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:46:05+00:00 2026-05-25T00:46:05+00:00

Picture this DTO-like class: class LineItem : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public

  • 0

Picture this DTO-like class:

class LineItem : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public string Description { get; set; }

    private decimal m_Amount;
    public decimal Amount
    {
        get { return m_Amount; }
        set
        {
            if (m_Amount == value)
                return;
            m_Amount = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("Amount"));
        }
    }
}

And a binding like this:

<ItemsControl ItemsSource="{Binding LineItems}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <DockPanel>
                <TextBox Text="{Binding Amount}"
                        DockPanel.Dock="Right" Width="50" />
                <TextBlock Text="{Binding Description}" />
            </DockPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

This would look something like:

enter image description here

Now, I want a total at the bottom. Moreover, I want it to update when Amount changes.

Something like this:

<TextBlock HorizontalAlignment="Right"
            Text="{Binding LineItems, 
            Converter={StaticResource MyConverter}}" />

For this:

enter image description here

But what is MyConverter? And, is it even a correct approach?

My question:

This does not work since the converter is called only the first time it is bound. I want it to reflect user changes, and I need to handle unknown quantity of LineItems. Certainly I am not the first to hit this. Is there a way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:46:06+00:00Added an answer on May 25, 2026 at 12:46 am

    The results are like this:

    enter image description here

    This is the CS:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    
        // used to force databinding to refresh
        public int FakeProperty
        {
            get { return (int)GetValue(FakePropertyProperty); }
            set { SetValue(FakePropertyProperty, value); }
        }
        public static readonly DependencyProperty FakePropertyProperty =
            DependencyProperty.Register("FakeProperty", 
            typeof(int), typeof(MainWindow), new UIPropertyMetadata(0));
    
        private void TextBox_TextChanged(object sender, 
            System.Windows.Controls.TextChangedEventArgs e)
        {
            FakeProperty++;
        }
    
    }
    
    public class Item : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public string Family { get; set; }
        private int m_Value;
        public int Value
        {
            get { return m_Value; }
            set
            {
                if (m_Value == value)
                    return;
                m_Value = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Value"));
            }
        }
    }
    
    public class Items : ObservableCollection<Item>
    {
        public Items()
        {
            this.Add(new Item { Family = "One", Value = 1 });
            this.Add(new Item { Family = "One", Value = 2 });
            this.Add(new Item { Family = "Two", Value = 3 });
            this.Add(new Item { Family = "Two", Value = 4 });
            this.Add(new Item { Family = "Two", Value = 5 });
            this.Add(new Item { Family = "Three", Value = 6 });
            this.Add(new Item { Family = "Three", Value = 7 });
        }
    }
    
    public class SumConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, 
                        object parameter, System.Globalization.CultureInfo culture)
        {
            var _Default = 0;
            if (values == null || values.Length != 2)
                return _Default;
            var _Collection = values[0] as System.Collections.IEnumerable;
            if (_Collection == null)
                return _Default;
            var _Items = _Collection.Cast<Item>();
            if (_Items == null)
                return _Default;
            var _Sum = _Items.Sum(x => x.Value);
            return _Sum;
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, obje
                        ct parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    And this XAML:

    xmlns:sort="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" Name="This"
    
    <Window.Resources>
        <local:Items x:Key="MyData" />
        <local:SumConverter x:Key="MyConverter" />
        <CollectionViewSource x:Key="MyView" Source="{StaticResource MyData}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Family" />
            </CollectionViewSource.GroupDescriptions>
            <CollectionViewSource.SortDescriptions>
                <sort:SortDescription PropertyName="Value" Direction="Ascending" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </Window.Resources>
    
    <StackPanel>
    
        <ItemsControl ItemsSource="{Binding Source={StaticResource MyView}}"
            Name="MyItemsControl">
            <ItemsControl.Resources>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <StackPanel>
                                    <!-- group header -->
                                    <Border Padding="10,5,0,5" Margin="0,10,0,10" 
                                            Background="Gainsboro" CornerRadius="10">
                                        <TextBlock FontWeight="Bold" 
                                                Text="{Binding Name}" />
                                    </Border>
                                    <!-- group items -->
                                    <ItemsPresenter Margin="10,0,0,0"/>
                                    <!-- group footer -->
                                    <Border BorderBrush="Black" 
                                                BorderThickness="0,.5,0,0"
                                                Margin="0,5,0,10">
                                        <TextBlock Width="100" 
                                                HorizontalAlignment="Right" 
                                                TextAlignment="Right" 
                                                Padding="0,0,5,0">
                                            <TextBlock.Text>
                                                <MultiBinding 
                                                 StringFormat="{}{0:C}"
                                                 Converter="{StaticResource MyConverter}">
                                                    <Binding Path="Items" />
                                                    <Binding Path="FakeProperty" 
                                                            ElementName="This"/>
                                                </MultiBinding>
                                            </TextBlock.Text>
                                        </TextBlock>
                                    </Border>
                                </StackPanel>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ItemsControl.Resources>
            <ItemsControl.GroupStyle>
                <GroupStyle ContainerStyle="{x:Null}" />
            </ItemsControl.GroupStyle>
            <ItemsControl.ItemTemplate>
                <DataTemplate DataType="ItemsPresenter">
                    <DockPanel>
                        <TextBox Text="{Binding Value, StringFormat={}{0:C}, 
                            UpdateSourceTrigger=PropertyChanged}" 
                            TextChanged="TextBox_TextChanged" 
                            TextAlignment="Right" DockPanel.Dock="Right"
                            Width="100" />
                        <TextBlock Text="{Binding Value, 
                            StringFormat={}Value is {0}}" 
                            FontWeight="Bold" Foreground="DimGray" />
                    </DockPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    
        <!-- list footer -->
        <Border BorderBrush="Black" BorderThickness="0,.5,0,0" Margin="0,5,0,10">
            <TextBlock Width="100" HorizontalAlignment="Right" TextAlignment="Right" 
                       Padding="0,0,5,0" FontWeight="Bold">
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource MyConverter}" 
                                  StringFormat="{}{0:C}">
                        <Binding Path="ItemsSource" ElementName="MyItemsControl" />
                        <Binding Path="FakeProperty" ElementName="This"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </Border>
    
    </StackPanel>
    

    What a nightmare to figure out!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a tab/widget/thingymajiggy like the feedback-thing in this picture: That behaves
Well, how to create picture link like this up or down votes (on the
I have this control (see picture). I like when check one option in this
in this picture,I can see: MenuStrip ,??, TextBox how do I an bar like
Look at this picture I've set its layer.cornerRadius to 15.0 and its layer.borderWidth to
I want to have Tab panel like this picture I want to implement the
I have a CSS layout as in this picture. I'd like to achieve the
I have a Gridview like this picture. Easyly in my last column, i keep
This picture shows a sample of what my columns look like in my crosstab
I have a database schema like this picture: I want to write a query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.