Welcome to the Xceed Community Sign in | Join | Help
Community Search  

How to use "GetStatContext"?

Sort Posts: Previous Next
  •  05-09-2008, 10:33 AM Post no. 12124

    How to use "GetStatContext"?

    Hi,

    after creating the columns and the DataGridCollectionView, I add a simple SumFunction to the StatFunctions:

     

    Xceed.Wpf.DataGrid.Stats.SumFunction sf = new Xceed.Wpf.DataGrid.Stats.SumFunction("AfterTaxSum", "AfterTax");

    _dataGridCollectionView.StatFunctions.Add(sf);

     

    My XAML contains a TextBox

     

    <TextBox x:Name="txtSum1" />

     

    How do I bind the TextProperty of txtSum1 to the AfterTaxSum-function?

     

    I do not have/want a StatRow/StatCell in the grid.

     

    Looking at the examples in the documentation I tried

     

    Text="{Binding Path=StatContext.AfterTaxSum,ElementName=myGrid}"

     

    That does not work.

    Also, I tried to do the binding in code

     

    NewBinding = new Binding("StatContext.AfterTaxSum");

    NewBinding.Mode = BindingMode.OneWay;

    NewBinding.Source = myGrid;

    txtSum1.SetBinding(TextBox.TextProperty, NewBinding);

     

    That doesn't work either.

     

    Last idea I have is using the static method GetStatContext, but I do not know which

    element to provicde to the parameter of this function.

     

    Any hints on how to get this working?

     

    Michael.

     

  •  05-09-2008, 3:02 PM Post no. 12129 in reply to 12124

    Re: How to use "GetStatContext"?

    What exactly is not working? Is it possible that you have binding errors in your output window? StatContext is a readonly attached property, hence the GetStatContext method.

    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  05-25-2008, 8:33 AM Post no. 12487 in reply to 12129

    Re: How to use "GetStatContext"?

    Hi Jenny,

     

    yes I do get binding errors in the output window.

    I would like to know how to properly use the GetStatContext-Method.

    Do you have an example?

     

    Greetings,

    Michael.

     

  •  05-26-2008, 9:12 AM Post no. 12493 in reply to 12487

    Re: How to use "GetStatContext"?

    The Stat Functions topic in the documentation provides examples of how to use the StatContext attached property.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  06-02-2008, 7:00 AM Post no. 12612 in reply to 12493

    Re: How to use "GetStatContext"?

    And which example do you mean?

    There should be 4 examples, but only 2 and 4 actually contain any code.

    Examples 1 and 3 are empty.

     

    Michael.

     

  •  06-02-2008, 11:02 AM Post no. 12614 in reply to 12612

    Re: How to use "GetStatContext"?

    Example 3 clearly demonstrates how to use the StatContext attached property. Here is the example (I will fix the documentation) 

    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
      <Grid.Resources>
        <xcdg:DataGridCollectionViewSource x:Key="cvs_orderdetails"
                                           Source="{Binding Source={x:Static Application.Current},
                                                            Path=OrderDetails}">
        <xcdg:DataGridCollectionViewSource.StatFunctions>
           <xcdg:CountFunction ResultPropertyName="orderid_count"
                               SourcePropertyName="OrderID"/>
           <xcdg:SumFunction ResultPropertyName="unitprice_sum"
                             SourcePropertyName="UnitPrice"/>
           <xcdg:AverageFunction ResultPropertyName="unitprice_average"
                                 SourcePropertyName="UnitPrice"/>
           <xcdg:SumFunction ResultPropertyName="quantity_sum"
                             SourcePropertyName="Quantity"/>
         </xcdg:DataGridCollectionViewSource.StatFunctions>      
          <xcdg:DataGridCollectionViewSource.GroupDescriptions>
            <xcdg:DataGridGroupDescription PropertyName="ProductID"/>
          </xcdg:DataGridCollectionViewSource.GroupDescriptions>
        </xcdg:DataGridCollectionViewSource>
       <xcdg:StatResultConverter x:Key="valueConverter"/>
      </Grid.Resources>
      <xcdg:DataGridControl x:Name="OrderDetailsGrid"
                            ItemsSource="{Binding Source={StaticResource cvs_orderdetails}}">
        <xcdg:DataGridControl.DefaultGroupConfiguration>
          <xcdg:GroupConfiguration>
            <xcdg:GroupConfiguration.Footers>
              <xcdg:GroupHeaderFooterItemTemplate VisibleWhenCollapsed="True">
                <DataTemplate>
                  <Border Background="#999999"
                          BorderBrush="LightBlue"
                          BorderThickness="3"
                          Margin="5" >
                    <Grid>
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                      </Grid.ColumnDefinitions>
                      <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                      </Grid.RowDefinitions>
                      <TextBlock Text="Total Orders: " Grid.Row="0" Grid.Column="0"/>
                       <TextBlock Text="{Binding RelativeSource={RelativeSource Self},
                                                 Path=(xcdg:DataGridControl.StatContext).orderid_count}"
                                  Grid.Row="0" Grid.Column="1"/>
                       
                        <TextBlock Text="Total Quantity Sold: " Grid.Row="1" Grid.Column="0"/>
                       <TextBlock Text="{Binding RelativeSource={RelativeSource Self},
                                       Path=(xcdg:DataGridControl.StatContext).quantity_sum}"
                                       Grid.Row="1" Grid.Column="1"/>
     
                        <TextBlock Text="Total Sales: " Grid.Row="2" Grid.Column="0"/>
                       <TextBlock Text="{Binding RelativeSource={RelativeSource Self},
                                                 Path=(xcdg:DataGridControl.StatContext).unitprice_sum}"
                                  Grid.Row="2" Grid.Column="1"/> 
                        <TextBlock Text="Average Unit Price: " Grid.Row="3" Grid.Column="0"/>
                       <TextBlock Text="{Binding RelativeSource={RelativeSource Self},
                                                 Path=(xcdg:DataGridControl.StatContext).unitprice_average,
                                                 Converter={StaticResource valueConverter},
                                                 ConverterParameter=f2}"
                                  Grid.Row="3" Grid.Column="1"/>
            
                      </Grid>
                    </Border>
                  </DataTemplate> 
                </xcdg:GroupHeaderFooterItemTemplate>
              </xcdg:GroupConfiguration.Footers>
            </xcdg:GroupConfiguration>
          </xcdg:DataGridControl.DefaultGroupConfiguration>
        </xcdg:DataGridControl>
      </Grid>


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.