0

我对 Silverlight 应用程序非常陌生。我最近一天一直在尝试这个,但我还是做不到。就我而言,它需要单击三下才能打开组合框。

我的 XAML 代码:

<sdk:DataGridTemplateColumn Header="Category" Width="100">
    <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate> 
            <ComboBox Name="cmbCategory"
                IsDropDownOpen="True" 
                ItemsSource="{Binding Source={StaticResource MyViewModel},Mode=OneWay,Path=pcProjTypeTaskCtry}" 
                DisplayMemberPath="TaskCtgyName" SelectedValuePath="TaskCtgy_FK" 
                SelectedValue="{Binding piTaskCtgy_FKField,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ToolTipService.ToolTip="{Binding psTaskCtgyNameField,UpdateSourceTrigger=PropertyChanged}"/> 
        </DataTemplate>

    </sdk:DataGridTemplateColumn.CellTemplate> 
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="SubCategory" Width="110">
    <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Name="tbSubCategory" Text="{Binding Path=psTaskSubCtgyNameField,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ToolTipService.ToolTip="{Binding psTaskSubCtgyNameField}" >
            </TextBlock>
        </DataTemplate> 
    </sdk:DataGridTemplateColumn.CellTemplate>
    <sdk:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <ComboBox ItemsSource="{Binding Source={StaticResource MyViewModel},Mode=TwoWay,Path=pcTaskSubCtry}" 
                DisplayMemberPath="TaskSubCtgyName" SelectedValuePath="TaskSubCtgyName" 
                SelectedItem="{Binding Source={StaticResource MyViewModel},Path=SelectedSubTask,Mode=TwoWay}" 
                SelectedValue="{Binding psTaskSubCtgyNameField,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                ToolTipService.ToolTip="{Binding psTaskSubCtgyNameField}"> 
            </ComboBox>
        </DataTemplate>
    </sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
4

1 回答 1

0

将 Dropdownopened 事件添加到组合框,然后将数据源分配给后端的组合框。

        var obj = (ComboBox)sender;
        obj.ItemsSource = Your list;
        obj.DisplayMemberPath = "pcTaskSubCtry";

在选择更改事件中,您可以通过投射所选项目来分配所选项目,如下所示。

 ComboBox cmbbox = (ComboBox)sender;
        if (cmbbox.SelectedValue != null)
        {
            Yourobject obj = new Yourobject() ;
            obj = MainDataGrid.SelectedItem as Yourobje;
            obj.pcTaskSubCtry= Yourobje.pcTaskSubCtry;
        }
于 2012-10-30T08:41:01.253 回答