Binding to non-static collection?
-
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.
-
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.
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 ProfileJust a grain of sand on the worlds beaches.