or
Dear Support,
I want to Binding to GridView.SelectedItems.Count or other DependencyProperty, but it returns nothing, no error no exception. Please help me how to Binding in telerik:GridViewColumn.Footer.
Other test results:
Code is below:
<
telerik:GridViewDataColumn
Header
=
"PO Number"
DataMemberBinding
=
"{Binding PONUMBER}"
>
<
telerik:GridViewDataColumn.AggregateFunctions
>
<
custom:CountDistinctFunction
Caption
=
"Distinct PO Count:"
/>
</
telerik:GridViewDataColumn.AggregateFunctions
>
<
telerik:GridViewDataColumn.Footer
>
<
StackPanel
Orientation
=
"Vertical"
Margin
=
"0"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"Selected:"
/>
<
TextBlock
Text
=
"{Binding ElementName=myGridView, Path=SelectedItems.Count}"
/>
</
StackPanel
>
<
telerik:AggregateResultsList
ItemsSource
=
"{Binding}"
VerticalAlignment
=
"Center"
>
<
ItemsControl.ItemTemplate
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
VerticalAlignment
=
"Center"
>
<
TextBlock
VerticalAlignment
=
"Center"
Text
=
"{Binding Caption}"
/>
<
TextBlock
VerticalAlignment
=
"Center"
Text
=
"{Binding FormattedValue}"
/>
</
StackPanel
>
</
DataTemplate
>
</
ItemsControl.ItemTemplate
>
</
telerik:AggregateResultsList
>
</
StackPanel
>
</
telerik:GridViewDataColumn.Footer
>
</
telerik:GridViewDataColumn
>
using System.Linq;
using System.Windows;
using NAPAData;
using System.Collections.ObjectModel;
namespace wpfNAPADashBoard.Pages
{
/// <
summary
>
/// Interaction logic for AcctInfo.xaml
/// </
summary
>
public partial class AcctInfo : Window
{
//Make a connection to the database Entity class context.
TAMSdbDataContext db = new TAMSdbDataContext();
//Access the user name saved to the iDictionary as part of the login process.
string uName = (string)App.Current.Properties["UserName"];
//Create an observable collection to bind the raddataform to. The collection is empty at this point.
ObservableCollection<
UserDetail
> obCol = new ObservableCollection<
UserDetail
>();
public AcctInfo()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//upon loading the window - LINQ query to populate the observable collection with a single record from the database
var userDetails =
from ud in db.UserDetails
where ud.UserName == uName
select ud;
foreach (var i in userDetails)
{
obCol.Add(i);
}
//Binds the observable collection to the dataform
AccountInfo.ItemsSource = obCol.ToList();
}
private void RadMenuItem_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
//Used by the RadMenu to close the window popup
this.Close();
}
private void AccountInfo_EditEnded(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndedEventArgs e)
{
//AccountInfo_EditEnded is used to save changes made to the observable collection to the database record using LINQ.
//First perform a LINQ query against the observable collection.
var result = (from o in obCol
select o);
//Now loop through the "result" query.
foreach (var x in result)
{
//LINQ query to pull the matching observable collection record from the database.
var userDetails =
from ud in db.UserDetails
where ud.UserName == uName
select ud;
//Apply the observable collection values to the LINQ query values.
foreach (var i in userDetails)
{
i.FirstName = x.FirstName;
i.LastName = x.LastName;
i.CompanyName = x.CompanyName;
i.Address1 = x.Address1;
i.Address2 = x.Address2;
i.Address3 = x.Address3;
i.City = x.City;
i.Region = x.Region;
i.Country = x.Country;
i.Phone = x.Phone;
i.WebSite = x.WebSite;
i.Email = x.Email;
//Save changes to the database
db.SubmitChanges();
}
}
}
}
}
<
Window
x:Class
=
"wpfNAPADashBoard.Pages.AcctInfo"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"Account Information"
WindowStartupLocation
=
"CenterScreen"
Height
=
"419"
Width
=
"806"
Loaded
=
"Window_Loaded"
>
<
Grid
>
<
Grid.Resources
>
<
DataTemplate
x:Key
=
"MyTemplate"
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
telerik:DataFormDataField
Grid.Row
=
"0"
Grid.Column
=
"0"
Label
=
"Client ID:"
DataMemberBinding
=
"{Binding ClientID, Mode=OneWay}"
IsEnabled
=
"False"
/>
<
telerik:DataFormDataField
Grid.Row
=
"1"
Grid.Column
=
"0"
Label
=
"Company Name:"
DataMemberBinding
=
"{Binding CompanyName, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"2"
Grid.Column
=
"0"
Label
=
"Address 1:"
DataMemberBinding
=
"{Binding Address1, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"3"
Grid.Column
=
"0"
Label
=
"Address 2:"
DataMemberBinding
=
"{Binding Address2, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"4"
Grid.Column
=
"0"
Label
=
"Address 3:"
DataMemberBinding
=
"{Binding Address3, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"5"
Grid.Column
=
"0"
Label
=
"City:"
DataMemberBinding
=
"{Binding City, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"6"
Grid.Column
=
"0"
Label
=
"State/Region:"
DataMemberBinding
=
"{Binding Region, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"7"
Grid.Column
=
"0"
Label
=
"PostalCode:"
DataMemberBinding
=
"{Binding PostalCode, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"8"
Grid.Column
=
"0"
Label
=
"Country:"
DataMemberBinding
=
"{Binding Country, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"0"
Grid.Column
=
"1"
Label
=
"Company ID:"
DataMemberBinding
=
"{Binding CompanyID, Mode=OneWay}"
IsEnabled
=
"False"
/>
<
telerik:DataFormDataField
Grid.Row
=
"1"
Grid.Column
=
"1"
Label
=
"First Name:"
DataMemberBinding
=
"{Binding FirstName, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"2"
Grid.Column
=
"1"
Label
=
"Last Name:"
DataMemberBinding
=
"{Binding LastName, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"3"
Grid.Column
=
"1"
Label
=
"Email:"
DataMemberBinding
=
"{Binding Email, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"4"
Grid.Column
=
"1"
Label
=
"Phone:"
DataMemberBinding
=
"{Binding Phone, Mode=TwoWay}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"5"
Grid.Column
=
"1"
Label
=
"Website:"
DataMemberBinding
=
"{Binding WebSite, Mode=TwoWay}"
/>
</
Grid
>
</
DataTemplate
>
</
Grid.Resources
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"auto"
/>
<
RowDefinition
Height
=
"*"
/>
</
Grid.RowDefinitions
>
<
telerik:RadMenu
Name
=
"radMenu1"
VerticalAlignment
=
"Top"
ClickToOpen
=
"True"
telerik:StyleManager.Theme
=
"Office_Black"
Grid.Row
=
"0"
>
<
telerik:RadMenuItem
Header
=
"Close"
Click
=
"RadMenuItem_Click"
/>
</
telerik:RadMenu
>
<
telerik:RadDataForm
x:Name
=
"AccountInfo"
AutoGenerateFields
=
"False"
ReadOnlyTemplate
=
"{StaticResource MyTemplate}"
EditTemplate
=
"{StaticResource MyTemplate}"
Grid.Row
=
"1"
telerik:StyleManager.Theme
=
"Office_Black"
CommandButtonsVisibility
=
"Cancel,Commit,Edit"
EditEnded
=
"AccountInfo_EditEnded"
>
</
telerik:RadDataForm
>
</
Grid
>
</
Window
>
var distinctValues = uxGrid.GetDistinctValues(column, true, null); var clip = string.Empty; int count = 0; Func<object, object> formatter; if (column.DataMemberBinding.Converter != null) { formatter = _ => column.DataMemberBinding.Converter.Convert(_, column.DataType, null, CultureInfo.CurrentUICulture); } else if (!string.IsNullOrEmpty(column.DataMemberBinding.StringFormat)) { formatter = _ => string.Format(_.ToString(), column.DataFormatString); } else { formatter = _ => _; } foreach (var value in distinctValues) { clip += formatter(value) + "\n"; count++; } clip = clip.TrimEnd('\n'); Clipboard.SetText(clip);
<
telerik:RadGridView.Resources
>
<
Style
TargetType
=
"{x:Type telerik:GridViewCell}"
>
<
Setter
Property
=
"Foreground"
Value
=
"Red"
/>
<
Style.Triggers
>
<
MultiDataTrigger
>
<
MultiDataTrigger.Conditions
>
<
Condition
Binding
=
"{Binding IsAllowedToEdit}"
Value
=
"True"
/>
<
Condition
Binding
=
"{Binding Path=Column.IsReadOnly, RelativeSource={RelativeSource Self}}"
Value
=
"False"
/>
</
MultiDataTrigger.Conditions
>
<
MultiDataTrigger.Setters
>
<
Setter
Property
=
"Background"
Value
=
"#DBFFEC"
/>
</
MultiDataTrigger.Setters
>
</
MultiDataTrigger
>
</
Style.Triggers
>
</
Style
>
</
telerik:RadGridView.Resources
>