I try to use a custom control with a DependencyProperty binding for the columns in a DataGrid. Everything is working up to the point where I select a row.
My custom control ShiftControl.xaml:
<UserControl x:Class="xRoster.UserControls.ShiftControl"
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:xRoster.UserControls">
<TextBlock x:Name="tbShift"
Text="{Binding Path=Shift}"
TextWrapping="Wrap"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</UserControl>
My code-behind for the ShiftControl.xaml.cs:
public partial class ShiftControl : UserControl
{
public ShiftControl()
{
InitializeComponent();
tbShift.DataContext = this;
}
public static readonly DependencyProperty ShiftProperty =
DependencyProperty.Register(
"Shift", typeof(string), typeof(ShiftControl));
public string Shift
{
get { return (string)GetValue(ShiftProperty); }
set { SetValue(ShiftProperty, value); }
}
}
The code where I use the ShiftControl in a DataGrid window.xaml:
<UserControl.Resources>
<DataTemplate x:Key="day1Column">
<uc:ShiftControl Shift="{Binding Day1Shift.Display}"/>
</DataTemplate>
</UserControl.Resources>
<DataGrid ItemsSource="{Binding Employees}"
AutoGenerateColumns="False"
HeadersVisibility="Column"
RowHeight="50">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Montag"
HeaderStyle="{StaticResource columnHeaderStyle}"
CellTemplate="{StaticResource day1Column}"
CellEditingTemplate="{StaticResource day1Column}"/>
</DataGrid.Columns>
</DataGrid>
As I said, the Binding for my ShiftControl is working only when the Row where it is placed is not selected.
Any Ideas? Thanks in advance