Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Binding to property in data template
posted

I am using the XamDataGrid and adding one column for every day within a date range, hence I don't know the number of columns until the date range has been selected.

To achieve this, I am manually adding unbound columns to the grid.

This achieves the effect: col1, col2, col3, col4, col5

I have a collection which has two properties, Quantity and Production Date, I have bound my columns to the quantity field using the BindingPath property of the Unbound field.

What I wanted to do is add a checkbox to the header of the column, which I achieved using a data template.

<Style x:Key="CheckBoxHeaderStyle" TargetType="{x:Type igWPF:LabelPresenter}">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />

<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Name="HeaderCheckBox"
FlowDirection="RightToLeft"
IsChecked="{Binding Path=., Converter={StaticResource dateStringToBooleanConverter}}" >
<CheckBox.Content>
<TextBlock Name="HeaderTextBlock" Text="{Binding}"></TextBlock>
</CheckBox.Content>
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=HeaderCheckBox, Path=IsChecked}" Value="True">
<Setter Property="Foreground" Value="White" />
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
<StackPanel.Style>
<Style TargetType="StackPanel">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=HeaderCheckBox,Path=IsChecked}" Value="True">
<Setter Property="Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
</StackPanel>

</DataTemplate>
</Setter.Value>
</Setter>
</Style>

The question is: how do I bind any value to the checked property of this data template? I want to be able to set certain columns to be checked when the grid loads and then get the columns that have been checked by the user whilst using the grid.

I cant find any solution for this that works effectively, please help

Parents Reply Children
No Data