I am creating a project where i need to allow user to allow filter and sorting,grouping and alternatebackground colors.. i have created an sample of what and how i am doing. with allowfilter. Could anybody help me out where i am doing wrong.
here are my code.
<Window x:Class="BindingSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:local="clr-namespace:BindingSample" xmlns:igcp="clr-namespace:Infragistics;assembly=InfragisticsWPF4.Controls.Editors.XamColorPicker.v12.1" Title="MainWindow" Height="350" Width="525"> <TabControl> <TabItem Header="Data Grid"> <igDP:XamDataGrid DataSource="{Binding Peoples}"> <igDP:XamDataGrid.Resources> <Style x:Key="{x:Type igDP:DataRecordCellArea}" TargetType="{x:Type igDP:DataRecordCellArea}"> <Setter Property="BackgroundAlternate" Value="{Binding Settings.AlternateBackground,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> <Style.Triggers> <!-- Highlight the records that are filtered in as an orange gradient--> <Trigger Property="IsFilteredOut" Value="false"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0" Color="#FFfffadc" /> <GradientStop Offset="1" Color="#FFffda5b" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <!-- Highlight the records that are filtered out as a light grey--> <Trigger Property="IsFilteredOut" Value="true"> <Setter Property="Background" Value="#FFF1F1F1" /> </Trigger> </Style.Triggers> </Style> <!-- You can style the filter cells using FilterCellValuePresenter. The following style highlights filter cells that have active filters.--> <Style x:Key="{x:Type igDP:FilterCellValuePresenter}" TargetType="{x:Type igDP:FilterCellValuePresenter}"> <Style.Triggers> <Trigger Property="HasActiveFilters" Value="true"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0" Color="#FFfffadc" /> <GradientStop Offset="1" Color="#FFffda5b" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowRecordFiltering="{Binding Settings.AllowFilter}"/> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout Key="{x:Type local:People}"> <igDP:FieldLayout.Settings> <igDP:FieldLayoutSettings HighlightAlternateRecords="True" FilterAction="Disable"/> </igDP:FieldLayout.Settings> <igDP:FieldLayout.Fields> <igDP:Field Name="Id" Column="0" Label="Serial No" Row="0" /> <igDP:Field Name="Name" Column="0" Label="Name" Row="0" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </TabItem> <TabItem Header="Settings"> <StackPanel> <CheckBox IsChecked="{Binding Settings.AllowFilter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Content="Allow Filter" Margin="10"/> </StackPanel> </TabItem> </TabControl></Window>
public partial class MainWindow : Window, INotifyPropertyChanged { private ObservableCollection<People> _Peoples; public ObservableCollection<People> Peoples { get { return _Peoples; } set { _Peoples = value; } } private GridSettings _settings; public GridSettings Settings { get { return _settings; } set { _settings = value; OnChanged("Settings"); } } public MainWindow() { InitializeComponent(); Loaded += new RoutedEventHandler(MainWindow_Loaded); } void MainWindow_Loaded(object sender, RoutedEventArgs e) { Peoples = new ObservableCollection<People>(); for (int i = 0; i < 10; i++) { Peoples.Add(new People() { Id = i + 1, Name = "Name" + i.ToString() }); } this.DataContext = this; } public event PropertyChangedEventHandler PropertyChanged; public void OnChanged(string Name) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(Name)); } } } public class People : INotifyPropertyChanged { private int _Id; public int Id { get { return _Id; } set { _Id = value; OnChanged("Id"); } } private string _Name; public string Name { get { return _Name; } set { _Name = value; OnChanged("Name"); } } public event PropertyChangedEventHandler PropertyChanged; public void OnChanged(string Name) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(Name)); } } } public class GridSettings : INotifyPropertyChanged { private bool _AllowFilter; public bool AllowFilter { get { return _AllowFilter; } set { _AllowFilter = value; OnChanged("AllowFilter"); } } private Brush _AlternateBackground; public Brush AlternateBackground { get { return _AlternateBackground; } set { _AlternateBackground = value; OnChanged("AlternateBackground"); } } public event PropertyChangedEventHandler PropertyChanged; public void OnChanged(string Name) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(Name)); } } }
Hello,
Thnak you for your feedback. I am very glad that you resolved your issue. If I think of another workaround for you I will let you know.
Thanks again.
Hi Stefan,
Thanks for valuable reply. i already found this solution on other posts. but this is not helpful in my case where view and settings view are spread over multiple projects. i found these three ways. hopefully these could help others too.
Currently i am going with behaviors because this one only help to out yet.
if you have any other way to bind the inner properties which are not on the same visual tree please provide the samples. or guidelines.
Thanks Again.
Regards
J S Jodha
I have been looking into your original post and I have created a sample project for you with the functionality you want. Basically the FieldSettings doesn’t have DataContext, so you can bind its Properties only to a StaticResources, so I instantiated your GridSettings in the XamDataGrid’s Resources and set it to the Settings Property. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
thanks.
I already tried that one. but still it not working.
I'm not sure if this is the only issue, but it looks like you did not instanciate your settings!
Try with
private GridSettings _settings = new GridSettings();
in your MainWindow.
Cheers,
Awen