I've created custom control (Add/Subtract column on picture) and put it to DataGridTemplateColumn of DataGrid control:
<DataGridTextColumn Binding="{Binding Count}" Header="Count" Width="60"/>
<DataGridTemplateColumn Width="90" Header="Add/Substract">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<controls:AddSubtractControl HorizontalAlignment="Center" AddSubtractEvent="AddSubtractClick" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
The main task of my custom control, is of course add/subtract some value to actual value located on "Count" column.
When user click "add" button, the control call some event with entered value:
private void AddClick(object sender, MouseButtonEventArgs e)
{
AddSubstractEvent(int.Parse(countBox.Text), e);
}
When I click "add" or "subtract" button, before AddClick method, in some unknown cases the contructor of this control is called first. Thus countBox.Text has default value, not entered before clicking "add" button.
How to deal with this issue? Thanks for any help.