Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
295
XamDataGrid Settings Binding
posted

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));
            }
        }
    }