如何在Silverlight Datagrid Dropdown SelectionChanged事件中找到Label控件

时间:2013-08-01 01:24:45

标签: silverlight-4.0 datagridtemplatecolumn dropdownbox

我正在使用SiverLight Datagrid,其中有一个下拉列表和标签 在Dropdown SelectedIndexChanged事件中,我想找到标签并分配DropdownList的选定值。

Xaml Page:

 <sdk:DataGridTemplateColumn  Header="New Receipe" CanUserSort="True" >
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>

                                <Border Style="{StaticResource GridBackgroundBorder}"  Background="{Binding Path=IsActive, Converter={StaticResource BoolToBackgroundValueConverter1}}"></Border>
                                <sdk:Label Margin="5,0,5,0" x:Name="lblCompVer" Content="{Binding Path=Version}" Height="Auto" VerticalAlignment="Center" Foreground="{Binding Path=IsActive, Converter={StaticResource BoolToForegroundValueConverter1}}"/>
                            </Grid>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                    <sdk:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <Grid>
                                <ComboBox Height="Auto" SelectionChanged="cboCompVerSel_SelectionChanged" x:Name="cboCompVerSel" ItemsSource="{Binding Path=CompVerList,Mode=TwoWay}" SelectedItem="{Binding Mode=OneWay, Path=Version}" Visibility="{Binding Path=IsActive, Converter={StaticResource BoolToVisibilityValueConverter1}}"/>
                            <!--<TextBox Height="Auto" Text="{Binding Mode=TwoWay, Path=Version}" x:Name="TextBoxCodeVer" Visibility="{Binding Path=IsActive, Converter={StaticResource BoolToVisibilityValueConverter1}}" AcceptsReturn="True"></TextBox>-->
                            </Grid>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellEditingTemplate>
                </sdk:DataGridTemplateColumn>

DropDownlist SelectionChanged事件:

 Private Sub cboCompVerSel_SelectionChanged(ByVal sender As System.Object, ByVal e As 

    System.Windows.Controls.SelectionChangedEventArgs)

        Dim src = TryCast(sender, ComboBox)

        If src IsNot Nothing Then 

           Dim fe As FrameworkElement = CType(src.Parent, FrameworkElement)

            Dim gridCmbo As Grid = DirectCast(fe, Grid)

            Dim lblCompVer As Label = CType(gridCmbo.FindName("lblCompVer"), Label)

            lblCompVer.DataContext = src.SelectedItem 

        End If
    End Sub

我无法识别lblCompVer控件以分配下拉列表选定值

1 个答案:

答案 0 :(得分:0)

这里是答案

Private Sub btnAssign_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        Dim btnAssign = TryCast(sender, Button)

        If btnAssign IsNot Nothing Then

            Dim columnUpdatedby As DataGridColumn = TaskDataGrid.Columns(15)
            Dim columntimestamp As DataGridColumn = TaskDataGrid.Columns(16)
            Dim feUpdatedby As FrameworkElement = columnUpdatedby.GetCellContent(TaskDataGrid.SelectedItem)
            Dim fetimestamp As FrameworkElement = columntimestamp.GetCellContent(TaskDataGrid.SelectedItem)

            Dim gridCmboUpdatedby As Grid = DirectCast(feUpdatedby, Grid)

            Dim gridCmbotimestamp As Grid = DirectCast(fetimestamp, Grid)

            Dim lblAssignedBy As Label = CType(gridCmboUpdatedby.FindName("lblAssignedBy"), Label)

            Dim lblAssignedTimestamp As Label = CType(gridCmbotimestamp.FindName("lblAssignedTimestamp"), Label)

            lblAssignedBy.Content = BCOMSCurrentUser.BCOMSUser.UserName
            lblAssignedTimestamp.Content = DateTime.Now.ToString()

        End If
    End Sub