Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Entity Framework Lists, Static Resources and Filtering a BindingListCollectionView

Entity Framework Lists, Static Resources and Filtering a BindingListCollectionView

Scheduled Pinned Locked Moved WCF and WF
csharpwpfwcftutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zx12a1
    wrote on last edited by
    #1

    Hi my view model has a dependency property ActiveWellLocation which is an ADO.Net Entity framework object, wellLocation, which is associated with wellSample which has an associated list wellAliquot, so: ActiveWellLocation.wellSample.wellAliquot - is a collection and I can successfully bind to my datagrid

    <dg:DataGrid x:Name="additivesDataGrid" HorizontalAlignment="Center" Margin="2" Width="302" Height="150"
    AutoGenerateColumns="False"

    ItemsSource="{Binding ActiveWellLocation.wellSample.wellAliquot}"
    ....
    </dg:DataGrid>

    I need to filter my wellAliquot collection and thus investigated indirecting thru a static resource. The following snippets of the CollectionViewSource and associated binding on the datagrid also bind ok:

    <CollectionViewSource Source="{Binding ActiveWellLocation.wellSample.wellAliquot}"
    x:Key="WellAliquotsWithAdditives" />

    with

    lt;dg:DataGrid x:Name="additivesDataGrid" HorizontalAlignment="Center" Margin="2" Width="302" Height="150"
    AutoGenerateColumns="False"
    ItemsSource="{Binding Source={StaticResource WellAliquotsWithAdditives}}"
    ....
    </dg:DataGrid

    I was intending to filter the CollectionViewSource (of type BindingListCollectionView) as my dp ActiveWellLocation updates. In short my view model fires an event to which the user control listens. In the event handler I have tried a couple of different ways to get hold of the resource but they fail, one example was

        public void PropertyChangedListener(object sender, PropertyChangedEventArgs e)
        {
            string name = e.PropertyName;
            switch (name)
            {
                case Avacta.Optim.Client.Models.PlateSampleViewModel.PLATE:
                    object srcWellAliquotsWithAdditives = this.Resources\["WellAliquotsWithAdditives"\];
                    BindingListCollectionView blcv = (BindingListCollectionView)CollectionViewSource.GetDefaultView(srcWellAliquotsWithAdditives);
                    blcv.CustomFilter = "additive <> null";
                    break;
                default:
                    break;
            }
        }
    

    To date I have been unable to get the resource and therefore the view. (also I expect the filter 'code' is not suitable, any clues to the correct filter appreciated) Any ideas as to the 'correct' approach? Cheers AndyF.

    S 1 Reply Last reply
    0
    • Z zx12a1

      Hi my view model has a dependency property ActiveWellLocation which is an ADO.Net Entity framework object, wellLocation, which is associated with wellSample which has an associated list wellAliquot, so: ActiveWellLocation.wellSample.wellAliquot - is a collection and I can successfully bind to my datagrid

      <dg:DataGrid x:Name="additivesDataGrid" HorizontalAlignment="Center" Margin="2" Width="302" Height="150"
      AutoGenerateColumns="False"

      ItemsSource="{Binding ActiveWellLocation.wellSample.wellAliquot}"
      ....
      </dg:DataGrid>

      I need to filter my wellAliquot collection and thus investigated indirecting thru a static resource. The following snippets of the CollectionViewSource and associated binding on the datagrid also bind ok:

      <CollectionViewSource Source="{Binding ActiveWellLocation.wellSample.wellAliquot}"
      x:Key="WellAliquotsWithAdditives" />

      with

      lt;dg:DataGrid x:Name="additivesDataGrid" HorizontalAlignment="Center" Margin="2" Width="302" Height="150"
      AutoGenerateColumns="False"
      ItemsSource="{Binding Source={StaticResource WellAliquotsWithAdditives}}"
      ....
      </dg:DataGrid

      I was intending to filter the CollectionViewSource (of type BindingListCollectionView) as my dp ActiveWellLocation updates. In short my view model fires an event to which the user control listens. In the event handler I have tried a couple of different ways to get hold of the resource but they fail, one example was

          public void PropertyChangedListener(object sender, PropertyChangedEventArgs e)
          {
              string name = e.PropertyName;
              switch (name)
              {
                  case Avacta.Optim.Client.Models.PlateSampleViewModel.PLATE:
                      object srcWellAliquotsWithAdditives = this.Resources\["WellAliquotsWithAdditives"\];
                      BindingListCollectionView blcv = (BindingListCollectionView)CollectionViewSource.GetDefaultView(srcWellAliquotsWithAdditives);
                      blcv.CustomFilter = "additive <> null";
                      break;
                  default:
                      break;
              }
          }
      

      To date I have been unable to get the resource and therefore the view. (also I expect the filter 'code' is not suitable, any clues to the correct filter appreciated) Any ideas as to the 'correct' approach? Cheers AndyF.

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #2

      Usually I use: FindResource() (instead of Resources[key]) Also I dunno if it's the right event but... if this is called before InitializeComponent() returns, your ResourceDictionary might be null. Hence it's a reasonable idea to test for / expect a null value. And then what is "this"? Is it the UI element where the collection is defined?

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

      Z 1 Reply Last reply
      0
      • S Super Lloyd

        Usually I use: FindResource() (instead of Resources[key]) Also I dunno if it's the right event but... if this is called before InitializeComponent() returns, your ResourceDictionary might be null. Hence it's a reasonable idea to test for / expect a null value. And then what is "this"? Is it the UI element where the collection is defined?

        A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

        Z Offline
        Z Offline
        zx12a1
        wrote on last edited by
        #3

        Thanks for the thoughts. You are right, the event is fired too early even though it appears after the various code required to 'load' the data. The GUI (this) is a user control and its main property dependency ActiveWell is synchronized with a property on an associated control. The associated control sets the ActiveWell property on this control. This control listens to its change property events and 'loads' the entity graph, as described above, and then fies another event. The control listens to its own events and attemps to get the collectioin for filtering..... So far so bad.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups