Click here to Skip to main content
15,881,172 members
Articles / Desktop Programming / WPF

Visual Expression Builder for Dynamic Linq

Rate me:
Please Sign up or sign in to vote.
4.73/5 (14 votes)
2 Feb 2012CPOL4 min read 111.5K   2.4K   96  
Let your users create their own Linq filters with this MVVM WPF tool you can include in your application
<UserControl x:Class="ChabadOnCampus.DynamicLinq.DynamicLinqUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="403"
             >
        <ListView ItemsSource="{Binding}" >
            <ListView.CommandBindings>
                <CommandBinding Command="Delete" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed" />
            </ListView.CommandBindings>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="50" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="200" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <ComboBox Grid.Column="0" ItemsSource="{Binding AvailableCombinationOperators}" SelectedItem="{Binding CombineOperator}" />
                        <ComboBox Grid.Column="1" ItemsSource="{Binding AvailableProperties}" SelectedItem="{Binding PropertyInfo}" DisplayMemberPath="Name" />
                        <ComboBox Grid.Column="2" ItemsSource="{Binding AvailableCompareOperators}" SelectedItem="{Binding CompareOperator}" />
                        <!--<TextBox Text="{Binding Value2.Value}" Grid.Column="3" />-->
                    <ContentControl Content="{Binding ValueControl}" Grid.Column="3"/>
                    <Button Grid.Column="4" Content="Delete" Command="Delete" CommandParameter="{Binding}" Margin="10,0,0,0" />
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
         </ListView>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Co-director of Chabad Student Center @ SUNY New Paltz
Lecturer of Computer Science @ SUNY New Paltz

Comments and Discussions