B
Bill McCormick
I'm trying to bind some object data to a ListView contained within a
UserControl as follows:
<!--MyDataGrid.xmal-->
<UserControl x:Class="MyDataGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<ObjectDataProvider
x:Key="MyData"
MethodName="LoadMyData" />
</UserControl.Resources>
<Grid DataContext="{StaticResource MyData}">
<DockPanel>
<ListView ItemsSource="{Binding}">
...
</ListView >
</DockPanel>
</Grid>
</UserControl>
//MyDataGrid.xmal.cs
namespace MyNameSpace {
/// <summary>
/// Interaction logic for MyDataGrid.xaml
/// </summary>
public partial class MyDataGrid: UserControl {
public MyDataCollection myData;
public MyDataGrid() {
InitializeComponent();
}
public void LoadMyData() {
myData = SomeCommandToLoadData();
}
}
}
I've had to change the names to protect the innocent, but it does
compile and run. It's just that the LoadMyData method is never called.
Does anybody out there know how to do this?
Thanks,
Bill
UserControl as follows:
<!--MyDataGrid.xmal-->
<UserControl x:Class="MyDataGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<ObjectDataProvider
x:Key="MyData"
MethodName="LoadMyData" />
</UserControl.Resources>
<Grid DataContext="{StaticResource MyData}">
<DockPanel>
<ListView ItemsSource="{Binding}">
...
</ListView >
</DockPanel>
</Grid>
</UserControl>
//MyDataGrid.xmal.cs
namespace MyNameSpace {
/// <summary>
/// Interaction logic for MyDataGrid.xaml
/// </summary>
public partial class MyDataGrid: UserControl {
public MyDataCollection myData;
public MyDataGrid() {
InitializeComponent();
}
public void LoadMyData() {
myData = SomeCommandToLoadData();
}
}
}
I've had to change the names to protect the innocent, but it does
compile and run. It's just that the LoadMyData method is never called.
Does anybody out there know how to do this?
Thanks,
Bill