I'm coding a Phone book manger C# WPF application,it consist of a data grid which is bind to observal collection
one of the data grid columnis is DataGridTemplateColumn,in edit mode it's consist of a text box and list box as below
Expand|Select|Wrap|Line Numbers
-
- <DataGridTemplateColumn.CellEditingTemplate>
- <DataTemplate>
- <StackPanel>
- <DockPanel Style="{StaticResource DockPanstyle}">
- <Button Name="addConBut" DockPanel.Dock="Left" Click="addConBut_Click" Style="{StaticResource ButStyle}" Template="{StaticResource addButCT}"/>
- <Button Name="delConBut" DockPanel.Dock="Right" Click="delConElementBut_Click" Style="{StaticResource ButStyle}" Template="{StaticResource delButCT}"/>
- </DockPanel>
- <TextBox Name="hTxtBox" Margin="2,6" LostFocus="txtBoxTemp_LostFocus" >
- <TextBox.Text>
- <MultiBinding Converter="{StaticResource mulBindConv}" UpdateSourceTrigger="Explicit">
- <Binding Path="AddHomeNumber" ValidatesOnDataErrors="True" ValidatesOnExceptions="True" NotifyOnValidationerror="True" Mode="OneWayToSource">
- <Binding.ValidationRules>
- <MyClasses:ContactValidation CheckFor="Home"></MyClasses:ContactValidation>
- </Binding.ValidationRules>
- </Binding>
- <Binding ElementName="hnList" Path="SelectedItem" Mode="OneWay"></Binding>
- </MultiBinding>
- </TextBox.Text>
- </TextBox>
- <ListBox Name="hnList" ItemsSource="{Binding HomeNumbers}" DisplayMemberPath="HPhone" IsSynchronizedWithCurrentItem="True" />
- </StackPanel>
- </DataTemplate>
- </DataGridTemplateColumn.CellEditingTemplate>
i want the source to be updated when pressing the add button not when the editing TextBox or the entire row of the DataGrid Lost Focus, so i set UpdateSourceTrigger="Explicit" and i added a handler for the text box lost focus and its handler is "txtBoxTemp_LostFocus", i have added the following code in the handler
Expand|Select|Wrap|Line Numbers
- TextBox templ_txt_Bx = e.Source as TextBox;
- bindExpres=templ_txt_Bx.GetBindingExpression(TextBox.TextProperty);
Expand|Select|Wrap|Line Numbers
- if (bindExpres != null)
- {
- bindExpres.UpdateSource();
- }
bindExpres always equal null and i don't know why,does any one know why and how can i solve this issue