Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm a bit disappointed, because I really was hoping to approach this the way the sllev had suggested. To me, that seemed like the most logical way of doing it. There may still be a way, but I haven't figured it out.</p> <p>Here is how I ended up solving this problem. Basically what I did was add the "Tot" column to my DataSource (it was not there in my initial solution although it is in my question above). I bound my TextBox to that column, and then refreshed the ListView on the LostFocus event of the TextBox within the ListView. The Refresh() causes the SumConverter to be called again.</p> <p>Hopefully this helps someone else out - it seemed like a simple request but I have wasted a ton of time on it.</p> <p>MainWindow.xaml:</p> <pre><code>&lt;Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converters="clr-namespace:WpfApplication2" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;XmlDataProvider x:Key="myParties" XPath="Parties" Source="XMLFile1.xml" /&gt; &lt;CollectionViewSource x:Key="myCollectionViewSource" Source="{StaticResource myParties}" /&gt; &lt;converters:SumConverter x:Key="mySumConverter" /&gt; &lt;/Window.Resources&gt; &lt;StackPanel&gt; &lt;ListView x:Name="myListView" HorizontalAlignment="Stretch" ItemsSource="{Binding Source={StaticResource myCollectionViewSource},XPath='Party',Mode=TwoWay}"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Width="100" DisplayMemberBinding="{Binding XPath='@Contact'}" Header="Contact"/&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding XPath='@Qty'}" Header="Q"/&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding XPath='@Amount'}" Header="Amt"/&gt; &lt;GridViewColumn x:Name="tbTot" Header="Tot"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;DockPanel&gt; &lt;TextBox LostFocus="TextBox_LostFocus" Width="100" Text="{Binding XPath='@Tot'}" /&gt; &lt;/DockPanel&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;Label VerticalAlignment="Stretch"&gt; &lt;Label.Content&gt; &lt;MultiBinding Converter="{StaticResource mySumConverter}"&gt; &lt;Binding ElementName="myListView" Path="Items"/&gt; &lt;Binding ElementName="myListView" Path="Items.Count"/&gt; &lt;/MultiBinding&gt; &lt;/Label.Content&gt; &lt;/Label&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>CodeBehind on MainWindow.xaml:</p> <pre><code>Class MainWindow Public Sub New() ' This call is required by the designer. InitializeComponent() End Sub Private Sub TextBox_LostFocus(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) myListView.Items.Refresh() End Sub End Class </code></pre> <p>SumConverter.vb:</p> <pre><code>&lt;ValueConversion(GetType(Object()), GetType(String))&gt; Public Class SumConverter : Implements System.Windows.Data.IMultiValueConverter Public Function Convert(ByVal values() As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IMultiValueConverter.Convert Static lvItems As ItemCollection Static lvItem As Xml.XmlElement Dim nVal As Double Convert = 0 lvItems = values(0) If lvItems Is Nothing Then Exit Function For Each lvItem In lvItems 'Debug.Print(lvItem.GetAttribute("Tot")) If Double.TryParse(lvItem.GetAttribute("Tot"), nVal) Then Convert = Convert + nVal End If Next End Function Public Function ConvertBack(ByVal value As Object, ByVal targetTypes() As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object() Implements System.Windows.Data.IMultiValueConverter.ConvertBack ConvertBack = Nothing End Function End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload