0
對不起,對於長標題,但我想盡可能在標題中加入問題。在wpf datagrid列中顯示下拉列表,以便在數據單元格中的第一次鼠標單擊時顯示下拉列表
我有一個WPF數據網格,如下面的代碼所示。網格的交易欄有一個下拉菜單。當用戶點擊單元格時,它會選擇單元格。然後他們必須再次單擊單元格,才能進入單元格編輯模式並顯示下拉列表。然後他們必須再次單擊單元格以查看下拉列表。
我想知道是否有人能夠告訴我如何在第一次點擊下拉組合列表,而不是3次點擊,或者指向我爲了實現這一目的而應該做的事情。提前致謝。
<DataGrid SelectionMode="Single" Grid.Row="0" Name="grd_S_TML" CanUserAddRows="False" TabIndex="41" MinHeight="{Binding Grd_S_TMLHeight}" ItemsSource="{Binding GrdSTmlCollection}" SelectedIndex="{Binding GrdSTmlSelectedIndex}" SelectedItem="{Binding GrdSTmlSelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="false"
behaviors:DragManagerExtended.DragOverCommand="{Binding GrdStmlDragOverCommand}" behaviors:DragManagerExtended.DragDropCommand="{Binding GrdStmlDragDropCommand}" behaviors:DragManagerExtended.IsDropTarget="True" ContextMenu="{StaticResource mnuMGridPopUp}" CellStyle="{StaticResource OverrideGridCellHighlight}"
behaviors:DragManagerExtended.IsNeedToBeDisposed="{Binding IsFormClosed}">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding SequenceNo}" Width="0" Visibility="Collapsed" IsReadOnly="True" />
<DataGridTextColumn Header="Status" Binding="{Binding RowStatus}" Width="0" Visibility="Collapsed" IsReadOnly="True" />
<DataGridTemplateColumn Header="Trade" Width="201">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Left" Text="{Binding Path=TradeSelectedItem.Text}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox x:Name="cboTrades" ItemsSource="{Binding TradeCollection}" DisplayMemberPath="Text" SelectedValuePath="ID" SelectedItem="{Binding TradeSelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<behaviors:KeyPressedBehavior>
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window},Path=DataContext.RoleComboBoxKeyPressEvent}" />
</behaviors:KeyPressedBehavior>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Pay Rate" Width="60">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding PayRate, StringFormat={}{0:0.00}}" Style="{StaticResource TextBlockCenterAlligned}" TextAlignment="Right" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=PayRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="6" TextAlignment="Right" HorizontalContentAlignment="Right" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Qty" Width="60">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Quantity, StringFormat={}{0:0.00}}" Style="{StaticResource TextBlockCenterAlligned}" TextAlignment="Right" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Quantity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="6" TextAlignment="Right" HorizontalContentAlignment="Right" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Rate (p/hr)" Binding="{Binding Path=RateHR, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:0.00}}" Width="60" IsReadOnly="True" ElementStyle="{StaticResource RightAlignDataGridTextColumnStyle}" />
<DataGridTextColumn Header="Value (£)" Binding="{Binding ItemValue, StringFormat={}{0:0.00}}" Width="60" IsReadOnly="True" ElementStyle="{StaticResource RightAlignDataGridTextColumnStyle}" />
</DataGrid.Columns>
<i:Interaction.Behaviors>
<behaviors:DataGridColumnIndexAndCellPositionBehavior ColumnIndex="{Binding Source={StaticResource vmOrderPricing},Path=StmlColumnIndex,Mode=TwoWay}" />
<behaviors:DataGridRowClickBehavior RowClickCommand="{Binding GrdStmlMouseDownCommand}" />
<behaviors:DataGridCellEditEndingBehavior CellEditEndingCommand="{Binding GrdStmlAfterColUpdateCommand}" />
<behaviors:DataGridBeginningEditBehavior BeginningEditCommand="{Binding GrdStmlBeforeColEditCommand}" />
</i:Interaction.Behaviors>
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding GrdStmlLostFocusCommand}" />
</i:EventTrigger>
<behaviors:KeyPressedBehavior>
<i:InvokeCommandAction Command="{Binding GrdStmlKeyPressCommand}" />
</behaviors:KeyPressedBehavior>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding GrdStmlRowColChangeCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RowStatus}" Value="Edit"></Condition>
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=DataContext.LoadSalesOnly}" Value="false"></Condition>
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="{StaticResource ROW_STYLE_HIGHLIGHT_CHANGE}" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RowStatus}" Value="Add"></Condition>
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=DataContext.LoadSalesOnly}" Value="false"></Condition>
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="{StaticResource ROW_STYLE_HIGHLIGHT_NEW}" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RowStatus}" Value="Delete"></Condition>
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=DataContext.LoadSalesOnly}" Value="false"></Condition>
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="{StaticResource ROW_STYLE_HIGHLIGHT_DELETE}" />
</MultiDataTrigger>
<DataTrigger Binding="{Binding RowStatus}" Value="View">
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>