1

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

Xaml 页面:

 <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 控件来分配下拉选择的值

4

1 回答 1

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
于 2013-08-05T09:17:13.157 回答