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. WPF
  4. Binding to non-static collection?

Binding to non-static collection?

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpcsswcf
2 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    artwallacex
    wrote on last edited by
    #1

    I have a simple question that I hope someone can help me with. All of the Wpf examples that I have seen which bind a ListView to a collection do so by declaring the collection as static. How do you accomplish this with a non-static collection? Here is the typical example that I have run across:

    public partial class Window1: Window
    {
    public static ObservableCollection TheCollection = new ObservaleCollection();

    public Window1()
    {
        InitializeComponent();
    }
    

    }

    The XAML file:

    <Window.Resources>
    <CollectionViewSource Source="{Binding Source={x:Static local:Window1.TheCollection}}" x:Key="TheCollectionView"/>
    </Window.Resources>
    <Grid>
    <ListView Name="TheCollectionListView" ItemsSource="{Binding Source={StaticResource TheCollectionView}}" />
    </Grid>

    What is the syntax for the binding when the ObservableCollection is not static? I hate to ask what seems to be such a basic question but after several hours of searching I cannot find any example that does not use static.

    L 1 Reply Last reply
    0
    • A artwallacex

      I have a simple question that I hope someone can help me with. All of the Wpf examples that I have seen which bind a ListView to a collection do so by declaring the collection as static. How do you accomplish this with a non-static collection? Here is the typical example that I have run across:

      public partial class Window1: Window
      {
      public static ObservableCollection TheCollection = new ObservaleCollection();

      public Window1()
      {
          InitializeComponent();
      }
      

      }

      The XAML file:

      <Window.Resources>
      <CollectionViewSource Source="{Binding Source={x:Static local:Window1.TheCollection}}" x:Key="TheCollectionView"/>
      </Window.Resources>
      <Grid>
      <ListView Name="TheCollectionListView" ItemsSource="{Binding Source={StaticResource TheCollectionView}}" />
      </Grid>

      What is the syntax for the binding when the ObservableCollection is not static? I hate to ask what seems to be such a basic question but after several hours of searching I cannot find any example that does not use static.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Have a look at Bea's site. This post has what you are looking for: http://www.beacosta.com/blog/?p=17[^] Bea's if the "First Lady" of WPF data binding with many great examples of using the platform.

      Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

      Just a grain of sand on the worlds beaches.

      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