Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding Linq to an xceed datagrid.
Message
From
26/02/2008 16:12:49
 
 
To
26/02/2008 13:11:20
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01296509
Message ID:
01296587
Views:
21
WOOT! Finally I got it.

What worked for me was to just use Source="{Binding}" and set the DataContext in the code behind.

WPF c# codebehind:
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using cdsLinq;

namespace cdsProWPF
  {
  /// <summary>
  /// Interaction logic for cdsBillsWPF.xaml
  /// </summary>
  public partial class cdsBillsWPF : UserControl
    {
    cdsLinqDataContext dc;
    IEnumerable<cdsPayablesRecord> Bills { get; set; }

    public cdsBillsWPF()
      {
      dc = new cdsLinqDataContext();
      Bills = dc.GetPayables();
      DataContext = Bills;
      InitializeComponent();
      }

    private void MenuItem_Click(object sender, RoutedEventArgs e)
      {
      System.Windows.Forms.MessageBox.Show(dataGridControl1.CurrentItem.ToString());
      }
    }
  }
XAML:
<UserControl x:Class="cdsProWPF.cdsBillsWPF"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300" 
    xmlns:local="clr-namespace:cdsProWPF"             
    xmlns:xcdg="clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid"
    >
  <Grid>
    <Grid.Resources>
     <xcdg:DataGridCollectionViewSource x:Key="dgcvs" Source="{Binding}">
        <xcdg:DataGridCollectionViewSource.ItemProperties>
          <xcdg:DataGridItemProperty Name="DateDue" ValuePath="DateDue" Title="Date Due" />
          <xcdg:DataGridItemProperty Name="Name"    ValuePath="Name" Title="Account Name"  />
          <xcdg:DataGridItemProperty Name="Invoice" ValuePath="Invoice" Title="Invoice #" />
          <xcdg:DataGridItemProperty Name="Amount"  ValuePath="Amount" Title="Amount" />
        </xcdg:DataGridCollectionViewSource.ItemProperties>
      </xcdg:DataGridCollectionViewSource>
    </Grid.Resources>
    <xcdg:DataGridControl Name="dataGridControl1" ItemsSource="{Binding Source={StaticResource dgcvs}}" Margin="0,-3,0,3">
      <xcdg:DataGridControl.ContextMenu>
        <ContextMenu>
          <MenuItem Header="test" Click="MenuItem_Click" />
        </ContextMenu>
      </xcdg:DataGridControl.ContextMenu>
    </xcdg:DataGridControl>
  </Grid>
</UserControl>
Wow that took forever to get to work.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform