Фильтр на Silverlight Datagrid с использованием радио-кнопок C # - PullRequest
0 голосов
/ 09 января 2012

Я немного новичок в Silverlight и C # / XAML, и у меня есть проблема, которую я не могу понять.

У меня есть таблица данных:

<Grid x:Name="MainDataGrid" Grid.Row="5" >
                    <data:DataGrid x:Name="datagrid" AutoGenerateColumns="False" HorizontalAlignment="Stretch" IsReadOnly="True" VerticalAlignment="Top" ItemsSource="{Binding DataList}" Height="220" Margin="5">
                        <data:DataGrid.Columns>
                            <data:DataGridTextColumn Header="#" Binding="{Binding Number}" />
                            <data:DataGridTextColumn Header="Business Process" Width="300" Binding="{Binding BusinessProcess}" />
                            <data:DataGridTextColumn Header="Sub Process" Width="300" Binding="{Binding SubProcess}"  />
                            <data:DataGridTextColumn Header="ITAC" Width="100" Binding="{Binding Itac}"  />
                            <data:DataGridTextColumn Header="Status" Width="200" Binding="{Binding Status}" />
                        </data:DataGrid.Columns>
                    </data:DataGrid>
                </Grid>

, которая в настоящее время привязана к некоторым фиктивным данным, которые я создал во ViewModel:

 public class ItacViewModel : ViewModelBase
{
    public List<data> DataList { get; set; }

    public ItacViewModel()
    {
        var dataList = new List<data>
                           {
                               new data(1, "Fixed Asset", "Depreciation", "UL-AC1", "Under Review"),
                               new data(2, "Fixed Asset", "Depreciation", "UL-AC2", "Complete"),
                               new data(3, "Order to Cash", "Invoicing", "UL-AC3", "Under Review"),
                               new data(4, "Order to Cash", "Shipping Goods", "UL-AC4", "Under Review"),
                               new data(5, "Order to Cash", "Depreciation", "UL-AC5", "Complete"),
                               new data(6, "Order to Cash", "Depreciation", "UL-AC6", "Under Review"),
                               new data(7, "Order to Cash", "Depreciation", "UL-AC7", "Complete"),
                               new data(8, "Stock and Make", "Depreciation", "UL-AC8", "Under Review"),
                               new data(9, "Stock and Make", "Depreciation", "UL-AC9", "Under Review"),
                               new data(10, "General Accounting & Reporting", "Depreciation", "UL-AC10", "Complete")
                           };
        DataList = dataList;
    }
}

, и я хочу иметь возможностьфильтровать данные при выборе переключателя (имена переключателей совпадают с именами во втором столбце таблицы данных):

                            <StackPanel Margin="2">
                            <StackPanel Orientation="Horizontal" Margin="1">
                                <RadioButton GroupName="BusinessProcessesGroup" />
                                <TextBlock Text="All Business Processes" FontStyle="Italic" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="1">
                                <RadioButton GroupName="BusinessProcessesGroup" />
                                <TextBlock Text="Fixed Asset" FontStyle="Italic" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="1">
                                <RadioButton GroupName="BusinessProcessesGroup" />
                                <TextBlock Text="Order to Cash" FontStyle="Italic" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="1">
                                <RadioButton GroupName="BusinessProcessesGroup" />
                                <TextBlock Text="Purchase to Pay" FontStyle="Italic" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="1">
                                <RadioButton GroupName="BusinessProcessesGroup" />
                                <TextBlock Text="Stock and Make" FontStyle="Italic" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="1">
                                <RadioButton GroupName="BusinessProcessesGroup" />
                                <TextBlock Text="General Accounting and Reporting" FontStyle="Italic" />
                            </StackPanel>
                            <TextBlock Text=" " />
                        </StackPanel>

Пока я не смог выполнить эту работу, может кто-нибудь дать мненекоторые указатели, пожалуйста?

Спасибо заранее

Dom

РЕДАКТИРОВАТЬ Вот весь мой код на данный момент: MAINPAGE.XAML

    <UserControl x:Class="TabControl.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" mc:Ignorable="d"
    d:DesignHeight="500" d:DesignWidth="800">

    <Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <controls:TabControl Margin="3">
            <controls:TabItem Header="Local / Monitoring Controls" />
            <controls:TabItem Header="IBM Controls" />
            <controls:TabItem Header="ITAC's" >
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0">
                        <Border BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" >
                            <StackPanel Orientation="Horizontal" >
                                <TextBlock Text="ITAC's - IT Automated Controls in Key Financial Systems" FontSize="12" FontWeight="Bold" Margin="5" />
                                <StackPanel Orientation="Horizontal" Margin="5">
                                    <TextBlock Text="Date Last Updated: " />
                                    <TextBlock Text="Test Date, needs binding" />
                                </StackPanel>
                            </StackPanel>
                        </Border>
                        <Border BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2">
                            <TextBlock Text="ERP controls from Sirius" FontStyle="Italic" Margin="5" />
                        </Border>
                    </StackPanel>


                    <Grid x:Name="Controls" Grid.Row="1" Background="#A1AEC3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Border Grid.Row="0" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" Margin="1" >
                            <TextBlock Text="IT Automated Controls (Europe)" FontSize="12" FontWeight="Bold" Margin="5"/>
                        </Border>


                        <StackPanel Grid.Row="1" Grid.Column="0" Margin="0,0,10,0" >
                            <TextBlock Text="Total Active Controls" FontWeight="Bold" Margin="5,5,5,0" TextAlignment="Right" />
                            <TextBlock Text="ITAC's Under Review"  Margin="5,5,5,0" TextAlignment="Right"  />
                            <TextBlock Grid.Row="3" Grid.Column="0" Text="Outstanding Issues from Previous Months"  Margin="5,5,5,0" TextAlignment="Right"  />
                        </StackPanel>


                        <StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="10,0,0,0" >
                            <TextBox Width="200" TextAlignment="Center" Text="33" />
                            <TextBox Width="200" TextAlignment="Center" Text="5" />
                            <TextBox Width="200" TextAlignment="Center" Text="0" />
                        </StackPanel>


                    </Grid>

                    <Grid x:Name="ITACs" Grid.Row="2" Background="#A1AEC3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Border Grid.Row="0" Grid.Column="0" BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" Margin="1" >
                        <StackPanel Orientation="Horizontal" Margin="3">
                            <StackPanel Orientation="Horizontal" >
                                <RadioButton GroupName="BusinessProcessTitle" />
                                <TextBlock Text="All ITAC's" FontWeight="Bold" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="100,0,0,0" >
                                    <RadioButton GroupName="BusinessProcessTitle"  />
                                <TextBlock Text="ITAC's Requiring Review" FontWeight="Bold" />
                            </StackPanel>
                        </StackPanel>
                        </Border>

                        <Border Grid.Row="1" Grid.RowSpan="2" Grid.Column="0" BorderThickness="1" BorderBrush="WhiteSmoke" CornerRadius="2" Margin="1" >
                            <StackPanel Margin="2">
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <RadioButton GroupName="BusinessProcessesGroup" />
                                    <TextBlock Text="All Business Processes" FontStyle="Italic" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="1" />
                                    <TextBlock Text="Fixed Asset" FontStyle="Italic" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <RadioButton GroupName="BusinessProcessesGroup" />
                                    <TextBlock Text="Order to Cash" FontStyle="Italic" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <RadioButton GroupName="BusinessProcessesGroup" />
                                    <TextBlock Text="Purchase to Pay" FontStyle="Italic" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <RadioButton GroupName="BusinessProcessesGroup" />
                                    <TextBlock Text="Stock and Make" FontStyle="Italic" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <RadioButton GroupName="BusinessProcessesGroup" />
                                    <TextBlock Text="General Accounting and Reporting" FontStyle="Italic" />
                                </StackPanel>
                                <TextBlock Text=" " />
                            </StackPanel>
                        </Border>


                        <Border Grid.Row="0" Grid.Column="1" BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" Margin="1" >
                            <Grid >
                                <TextBlock Text="ITAC Description" FontWeight="Bold" HorizontalAlignment="Left" Margin="3" />
                                <TextBlock Text="UL-AC1" FontStyle="Italic" HorizontalAlignment="Right" Margin="3"/>
                            </Grid>
                        </Border>

                        <Border CornerRadius="2" Grid.Row="1" Grid.Column="1" BorderThickness="1" BorderBrush="WhiteSmoke">
                            <TextBlock TextWrapping="Wrap" Margin="3" 
                                   Text="Based on the asset class in the master data, the ERP system automatically calculates correct amounts for depreciation at the start of the depreciation run." />
                        </Border>
                        <Border CornerRadius="2" Grid.Row="2" Grid.Column="1" BorderThickness="1" BorderBrush="WhiteSmoke">
                            <StackPanel Orientation="Horizontal" Margin="1">
                                <TextBlock Text="Issue: " Margin="3,0,0,0" />
                                <TextBlock Text="Change Request to be created - Query Update Required" />
                            </StackPanel>
                        </Border>



                    </Grid>
                    <Grid x:Name="MainDataGrid" Grid.Row="5" >
                        <data:DataGrid x:Name="datagrid" AutoGenerateColumns="False" HorizontalAlignment="Stretch" IsReadOnly="True" VerticalAlignment="Top" ItemsSource="{Binding DataList}" Height="220" Margin="5">
                            <data:DataGrid.Columns>
                                <data:DataGridTextColumn Header="#" Binding="{Binding Number}" />
                                <data:DataGridTextColumn Header="Business Process" Width="300" Binding="{Binding BusinessProcess}" />
                                <data:DataGridTextColumn Header="Sub Process" Width="300" Binding="{Binding SubProcess}"  />
                                <data:DataGridTextColumn Header="ITAC" Width="100" Binding="{Binding Itac}"  />
                                <data:DataGridTextColumn Header="Status" Width="200" Binding="{Binding Status}" />
                            </data:DataGrid.Columns>
                        </data:DataGrid>
                    </Grid>

                </Grid>
            </controls:TabItem>
            <controls:TabItem Header="User Access" />
            <controls:TabItem Header="User Provisioning" />
            <controls:TabItem Header="About" />
        </controls:TabControl>
    </Grid>
</UserControl>

MAINPAGE.XAML.CS

    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.DataContext = new ItacViewModel();
        }
    }

DATA.CS

   public class data
    {
        public int Number { get; set; }
        public string BusinessProcess { get; set; }
        public string SubProcess { get; set; }
        public string Itac { get; set; }
        public string Status { get; set; }

        public data(int number, string businessProcess, string subProcess, string itac, string status)
        {
            Number = number;
            BusinessProcess = businessProcess;
            SubProcess = subProcess;
            Itac = itac;
            Status = status;
        }
    }

ITACVIEWMODEL.CS

открытый класс ItacViewModel: ViewModelBase {public List DataList {get;задавать;}

public ItacViewModel()
{
    var dataList = new List<data>
                       {
                           new data(1, "Fixed Asset", "Depreciation", "UL-AC1", "Under Review"),
                           new data(2, "Fixed Asset", "Depreciation", "UL-AC2", "Complete"),
                           new data(3, "Order to Cash", "Invoicing", "UL-AC3", "Under Review"),
                           new data(4, "Order to Cash", "Shipping Goods", "UL-AC4", "Under Review"),
                           new data(5, "Order to Cash", "Depreciation", "UL-AC5", "Complete"),
                           new data(6, "Order to Cash", "Depreciation", "UL-AC6", "Under Review"),
                           new data(7, "Order to Cash", "Depreciation", "UL-AC7", "Complete"),
                           new data(8, "Stock and Make", "Depreciation", "UL-AC8", "Under Review"),
                           new data(9, "Stock and Make", "Depreciation", "UL-AC9", "Under Review"),
                           new data(10, "General Accounting & Reporting", "Depreciation", "UL-AC10", "Complete")
                       };
    DataList = dataList;
}

}

Ответы [ 2 ]

0 голосов
/ 09 января 2012

Вот тривиальный способ: измените Visibility столбцов вашей таблицы данных в зависимости от состояния ваших радиокнопок.

XAML:

<data:DataGridTextColumn x:Name="colFixedAsset" Header="Status" Width="200" Binding="{Binding Status}" />
<RadioButton x:Name="radioFixedAsset" GroupName="BusinessProcessesGroup" IsChecked="False" Checked="radioFixedAsset_Checked" Unchecked="radioFixedAsset_Unchecked" />

Код позади:

private void radioFixedAsset_Checked(object sender, RoutedEventArgs e)
{
    this.colFixedAsset.Visibility = System.Windows.Visibility.Visible;
}

private void radioFixedAsset_Unchecked(object sender, RoutedEventArgs e)
{
    this.colFixedAsset.Visibility = System.Windows.Visibility.Collapsed;
}

Если вы пурист MVVM, добавьте логические свойства к вашей модели представления и свяжите свойства IsChecked ваших радиокнопок с этими логическими значениями.Также свяжите свойство Visibility ваших столбцов таблицы данных с этими логическими значениями, используя преобразователь .

0 голосов
/ 09 января 2012

Вместо привязки вашего DataGrid к List<data> вы должны привязать данные к ICollectionView .ICollectionView делает такие операции, как группировка, фильтрация и т. Д., Очень простыми для реализации на некоторых данных.

Взгляните на эту простую, но информативную статью о том, как добиться фильтрации в WPF через ICollectionView

Редактировать

Поскольку Silverlight не поддерживает стандартную реализацию ICollectionView, взгляните на this или this статья

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...