none
如何提取dataTemplate中的控件 RRS feed

  • 问题

  • <DataTemplate x:Key="酒店信息Style">
                    <Grid Name="grid2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20"/>
                            <ColumnDefinition Width="70"/>
                            <ColumnDefinition Width="0.5*"/>
                            <ColumnDefinition Width="70"/>
                            <ColumnDefinition Width="0.5*"/>
                            <ColumnDefinition Width="20"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="10"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Label Margin="5" Content="酒店名称:" Grid.Column="1" Grid.Row="1"/>
                        <TextBlock Margin="5" Grid.Column="2" Grid.Row="1" Text="{Binding 酒店ID,Converter={StaticResource 转酒店名称Convert}}"  />         
                        <Label Content="星   级:" Grid.Column="3" Margin="5" HorizontalContentAlignment="Right" Grid.Row="1"/>
                        <TextBlock Margin="5" Text="{Binding 星级, Converter={StaticResource 转代码名称Convert}}" Grid.Column="4" Grid.Row="1" />         
                        <Label Content="酒店地址:"  Grid.Row="2" Grid.Column="1" Margin="3" />
                        <TextBlock Text="{Binding 酒店地址}" Margin="5" Grid.Column="2" Grid.Row="2" />
                        <Label Content="地   区:" Grid.Row="2" Grid.Column="3" Margin="5" HorizontalContentAlignment="Right" />
                        <TextBlock Margin="5" Text="{Binding 地区, Converter={StaticResource 转代码名称Convert}}" Grid.Column="4" Grid.Row="2" />
                        <Label Content="门锁型号:" Grid.Row="3" Grid.Column="1" Margin="5" />
                        <TextBlock Text="{Binding 门锁型号ID}" Margin="5" Grid.Column="2" Grid.Row="3" />                              
                        <Label Content="数   量:" Grid.Column="3" Grid.Row="3" HorizontalContentAlignment="Right" Margin="5" />
                        <StackPanel Orientation="Horizontal" Margin="5,0,5,0" Grid.Column="4" Grid.Row="3">
                            <TextBlock HorizontalAlignment="Left" Margin="5,5,0,5" Width="60" Text="{Binding 数量}" />
                            <CheckBox  Margin="20,8" IsEnabled="False" IsChecked="{Binding 是否已发接口}" Content="已发接口" />
                        </StackPanel>
                        <Label Content="签单时间:" Margin="5" Grid.Row="4" Grid.Column="1" />
                        <TextBlock Margin="5" Grid.Row="4" Grid.Column="2" Text="{Binding 签单时间}" />
                        <Label Content="签单人:" Margin="5"  Grid.Row="4" Grid.Column="3" HorizontalContentAlignment="Right" />
                        <TextBlock Margin="5" Grid.Row="4" Grid.Column="4" Text="{Binding 签单人}" />         

                        <Label Content="安装时间:" Margin="5" Grid.Row="5" Grid.Column="1" />
                        <TextBlock Margin="5" Grid.Row="5" Grid.Column="2" Text="{Binding 安装时间}" />           
                        <Label Content="安装人:" Margin="5"  Grid.Row="5" Grid.Column="3" HorizontalContentAlignment="Right" />
                        <TextBlock Margin="5" Grid.Row="5" Grid.Column="4" Text="{Binding 安装人}" />

                        <DataGrid Name="dt联系人" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="4"  ItemsSource="{Binding}" CanUserAddRows="False" AutoGenerateColumns="False" RowHeaderWidth="20" IsEnabled="True" ColumnWidth="SizeToHeader">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="联系人职务" />
                                <DataGridTextColumn Header="联系人名称" />
                                <DataGridTextColumn Header="联系方式" />
                                <DataGridCheckBoxColumn Header="是否在职"/>
                                <DataGridTextColumn Header="备注" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </DataTemplate>

      <ContentControl Name="cc" Content="{Binding SelectedItem, ElementName=list酒店信息}" ContentTemplate="{StaticResource 酒店信息Style}" Grid.Column="1" Grid.Row="1" />

     

    上面是xaml代码,我如何能通过代码来获取dataTemplate中的dt联系人(DataGrid)的控件呢?

     

    2011年7月16日 2:22

答案