我有2个datagrid点击我在其他项目中添加项目,但是当我点击滚动条拇指或轴多次滚动时,在其他数据网格上添加项目请帮我这个
这里是代码
<DataGrid Name="dgMenu" Grid.Row="1" Grid.RowSpan="4" Margin="5,0,0,0" AutoGenerateColumns="False" RowHeight="25" AlternatingRowBackground="{StaticResource AlternateRowBackgroundBrush}" IsReadOnly="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
HeadersVisibility="Column" SelectionUnit="FullRow" ItemsSource="{Binding DgMenuCollection,Mode=TwoWay}" SelectedItem="{Binding DgSelectedMenu,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" PreviewKeyUp="dgMenu_PreviewKeyUp"
VerticalGridLinesBrush="{StaticResource GridLineColorBrush}" HorizontalGridLinesBrush="{StaticResource GridLineColorBrush}" Grid.Column="0" Grid.ColumnSpan="2" MouseDoubleClick="dgMenu_MouseDoubleClick">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource ButtonSelectedBrush}" />
<Setter Property="BorderBrush" Value="#A8E3FC" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="Code" Binding="{Binding PN_Recipe.RecipeCode}" />
<DataGridTextColumn Header="Recipe Name" Binding="{Binding PN_Recipe.RecipeName}"/>
<DataGridTextColumn Header="RecipeHalf Price" Binding="{Binding HalfMenuCost}" Visibility="Collapsed" />
<DataGridTextColumn Header="MenuFull Price" Binding="{Binding FullMenuCost}" Visibility="Collapsed"/>
</DataGrid.Columns>
</DataGrid>
答案 0 :(得分:0)
我认为问题是因为PreviewKeyUp="dgMenu_PreviewKeyUp"
而不是使用PreviewKeyUp,你可以使用鼠标双击事件来添加项目。
如果我弄错了,我道歉。
此致