Click here to Skip to main content
15,886,632 members
Articles / Desktop Programming / WPF

Dynamic LINQ to Entities Queries Using WCF/WPF Demo Code

Rate me:
Please Sign up or sign in to vote.
4.93/5 (86 votes)
30 Nov 2008CPOL22 min read 249.2K   4.5K   230  
Demonstrates a method of dynamic query across WCF Service boundaries.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfClient;assembly=">


    <!-- ScrollBarPageButton -->
    <Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="Transparent" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- VerticalScrolScrollBarThumblBar -->
    <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border 
          CornerRadius="4" 
          Background="Orange"
          BorderBrush="Orange" 
          BorderThickness="1" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- VerticalScrollBar -->
    <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid Background="Transparent" >
            <Grid.RowDefinitions>
                <RowDefinition Height="0.00001*"/>
            </Grid.RowDefinitions>
            <Border
      Grid.RowSpan="1"
      CornerRadius="2" 
      Background="Transparent" />
            <Track 
      Name="PART_Track"
      Grid.Row="1"
      IsDirectionReversed="true">
                <Track.DecreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageUpCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb 
          Style="{StaticResource ScrollBarThumb}" 
          Margin="3,0,3,0"  
          Background="Orange"
          BorderBrush="Orange" />

                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageDownCommand" />
                </Track.IncreaseRepeatButton>
            </Track>
        </Grid>
    </ControlTemplate>

    <!-- HorizontalScrollBar -->
    <ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid Background="Transparent" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.00001*"/>
            </Grid.ColumnDefinitions>
            <Border
      Grid.ColumnSpan="1"
      CornerRadius="2" 
      Background="Transparent" />
            <Track 
      Name="PART_Track"
      Grid.Column="1"
      IsDirectionReversed="False">
                <Track.DecreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageLeftCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb 
          Style="{StaticResource ScrollBarThumb}" 
          Margin="0,3,0,3"  
          Background="{TemplateBinding BorderBrush}"
          BorderBrush="{TemplateBinding BorderBrush}"/>
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageRightCommand" />
                </Track.IncreaseRepeatButton>
            </Track>
        </Grid>
    </ControlTemplate>

    <!-- ScrollBar -->
    <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="Width" Value="Auto"/>
                <Setter Property="Height" Value="14" />
                <Setter Property="Template" Value="{StaticResource HorizontalScrollBar}" />
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Width" Value="14"/>
                <Setter Property="Height" Value="Auto" />
                <Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <!-- ScrollViewerStyle -->
    <Style TargetType="{x:Type ScrollViewer}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="HorizontalScrollBarVisibility" Value="Visible" />
        <Setter Property="VerticalScrollBarVisibility" Value="Visible" />
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ContextMenu" Value="{x:Null}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <ScrollContentPresenter Grid.Column="0"/>

                        <ScrollBar Name="PART_VerticalScrollBar"
                            Grid.Column="1"
                            Value="{TemplateBinding VerticalOffset}"
                            Maximum="{TemplateBinding ScrollableHeight}"
                            ViewportSize="{TemplateBinding ViewportHeight}"
                            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                        <ScrollBar Name="PART_HorizontalScrollBar"
                            Orientation="Horizontal"
                            Grid.Row="1"
                            Grid.Column="0"
                            Value="{TemplateBinding HorizontalOffset}"
                            Maximum="{TemplateBinding ScrollableWidth}"
                            ViewportSize="{TemplateBinding ViewportWidth}"
                            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <!-- Brushes -->
    <SolidColorBrush x:Key="darkGreyBrush" Color="#FF656565"/>

    <SolidColorBrush x:Key="whiteSmokeBrush" Color="WhiteSmoke"/>

    <LinearGradientBrush x:Key="darkGreyBrushGradient" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF656565" Offset="0"/>
        <GradientStop Color="#FFFFFFFF" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="row0BasedBrush" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="#0E4791" Offset="0"/>
            <GradientStop Color="#468DE2" Offset="1"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>


    <LinearGradientBrush x:Key="row1BasedBrush"  StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="#D88" Offset="0"/>
            <GradientStop Color="#D31" Offset="1"/>
        </LinearGradientBrush.GradientStops>

    </LinearGradientBrush>


    <!-- toolButton -->
    <ControlTemplate x:Key="toolButton" TargetType="{x:Type Button}">
        <Grid Background="Transparent" Width="35" Height="35">

            <Ellipse x:Name="ell" 
                         Stroke="White" 
                         Fill="White"
                         HorizontalAlignment="Center" 
                         VerticalAlignment="Center"
                         Width="35" Height="35"
                         Margin="0" StrokeThickness="3" >
            </Ellipse>

            <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent},
                 Path=(local:ButtonProps.ImageUrl)}" HorizontalAlignment="Center" 
                 VerticalAlignment="Center"
                 Stretch="Fill" Width="20" Height="20"
                 Margin="0" />

        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="ell" Property="Stroke" Value="Black"/>
                <Setter TargetName="ell" Property="BitmapEffect">
                    <Setter.Value>
                        <OuterGlowBitmapEffect GlowColor="Black" GlowSize="10"/>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>



</ResourceDictionary>

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
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions