كيفية الوصول إلى التحكم في DataGrid.RowDetailsTemplate في وقت التشغيل


كيفية الوصول إلى txtName في DataGrid.RowDetailsTemplate في وقت التشغيل:

رمز بلدي :

ج #
<DataGrid ColumnWidth="*" Name="dgUsers" Grid.ColumnSpan="5" Grid.Row="4" Margin="10,0,10,4"
                                  AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
                                  IsReadOnly="True"
                                  SelectionMode="Single" SelectionUnit="FullRow" HeadersVisibility="Column">
                            <DataGrid.Columns>
                                <DataGridTextColumn x:Name="Name" Header="Name"  Binding="{Binding Path=Name}"/>
                                <DataGridTextColumn x:Name="Family" Header="Family"  Binding="{Binding Path=Family}"/>
                            </DataGrid.Columns>
                            <DataGrid.RowDetailsTemplate>
                                <DataTemplate>
                                    <Grid Margin="0,10,0,10" >
                                        <TextBox Name="txtName" Margin="0,2,0,2" Text="{Binding Path=Name}" />
                                        <TextBox Name="txtFamily" Margin="0,2,0,2" Text="{Binding Path=Family}" />
                                        <TextBox Name="txtUserName" Margin="0,2,0,2" Text="{Binding Path=UserName}"  />
                                            <Button Background="#FF7F9D0E" Height="60" Name="btnDelete" TabIndex="8" Width="60" Margin="30,0,30,0" Click="BtnDeleteClick">
                                    </Grid>

                                </DataTemplate>
                            </DataGrid.RowDetailsTemplate>
                        </DataGrid>

أريد الوصول إلى txtName في حدث BtnDeleteClick.

الحل 2

المطلوب RowDetailsTemplate المحتوى متاح فقط ثم يتم توسيع الصف.
حتى هذا الحدث (انظر تفاصيل التحميل) المحتوى فارغ وحاول العثور عليه DataGridDetailsPresenter.ContentTemplate يؤدي إلى استثناء:
System.InvalidOperationException

HRResult=0x80131509
الرسالة = العملية صالحة فقط للعناصر التي تستخدم هذا القالب.
Source=PresentationFramework
تتبع المكدس:
في System.Windows.FrameworkTemplate.FindName (اسم السلسلة، FrameworkElement templatedParent)
في ProductionOverviewModule.View.ProductionOrdersGrid.GetRowDetailTemplateGrids() في fileName.cs: السطر 86

للمزيد حول انظر الرابط https://stackoverflow.com/questions/5679648/why-would-this-contenttemplate-findname-throw-an-invalidoperationexception-on[^]

コメント

タイトルとURLをコピーしました