DI'm trying to expose the DataGrid.Columns property to the Ancestor UserControl like I did with the items source using the answer here. There doens't seem to be any properties available for me to bind the DataColumns in the following fashion:
<PagedDataGrid>
<PagedDataGrid.Columns>
<DataGridTextColumn Header="Custom Column"/>
<PagedDataGrid.Columns>
</PagedDataGrid>
Here's what I have so far. Do I need to do this in the code behind somehow?
XAML:
<UserControl x:Class="WpfPagedGrid.PagedDataGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfPagedGrid"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<WrapPanel><TextBlock>Paging Controls...</TextBlock></WrapPanel>
<DataGrid Name="dataGrid" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType=local:PagedDataGrid, AncestorLevel=1}, Path=ItemsSource}">
</DataGrid>
</Grid>
</UserControl>
C#:
namespace WpfPagedGrid {
public partial class PagedDataGrid : UserControl {
public PagedDataGrid() { InitializeComponent(); }
public IEnumerable ItemsSource {
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty = DataGrid.ItemsSourceProperty.AddOwner(typeof(PagedDataGrid));
//Does not work as there is no DataGrid.Columns property...
//public ObservableCollection<DataGridColumn> Columns {
//get { return (ObservableCollection<DataGridColumn>)GetValue(ColumnsProperty); }
//set { SetValue(ItemsSourceProperty, value); }
//}
//public static readonly DependencyProperty ColumnsProperty = DataGrid.CloumnsProperty.AddOwner(typeof(PagedDataGrid));
}
}
Edit: To clarify, I'm trying to specify columns on the user control and bind the DataGrid to those.