WPF Datagrid dgDataGrid_Loaded事件不止一次触发

时间:2013-04-24 05:20:15

标签: wpf wpfdatagrid loaded

我有一个wpf dadatagrid,每次加载内容时,dgDataGrid_Loaded事件都会触发两次。 我不确定这是WPF错误还是我错过了什么!?

这是我的Xaml代码:

<my:DataGrid Name="dgDataGrid" DockPanel.Dock="Top"
         AutoGenerateColumns="False"  ClipboardCopyMode="ExcludeHeader"                                              
         CanUserDeleteRows="True"
         SelectionMode="Extended"  SelectionUnit="FullRow"                              
         FontFamily="Tahoma"
         ItemsSource="{Binding}" 
         VirtualizingStackPanel.VirtualizationMode="Recycling"
         VirtualizingStackPanel.IsVirtualizing="True"
         EnableRowVirtualization="false"
         EnableColumnVirtualization="False"
         IsSynchronizedWithCurrentItem="True"
         BorderBrush="Blue" 
         RowBackground="White"
         HorizontalGridLinesBrush="Blue" 
         GridLinesVisibility="Horizontal" VerticalGridLinesBrush="Blue" IsTextSearchEnabled="False" 
         IsTabStop="True" HeadersVisibility="All"
         Loaded="dgDataGrid_Loaded" ContextMenuOpening="dgDataGrid_ContextMenuOpening"
         LoadingRow="dgDataGrid_LoadingRow">
            <my:DataGrid.Resources>

            </my:DataGrid.Resources>

            <my:DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type my:DataGridRow}}, Path=Header}"></TextBlock>
                </DataTemplate>
            </my:DataGrid.RowHeaderTemplate>
            <my:DataGrid.ColumnHeaderStyle>
                <Style TargetType="my:DataGridColumnHeader">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" Foreground="Blue"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </my:DataGrid.ColumnHeaderStyle>

            <my:DataGrid.ContextMenu>
                <ContextMenu Name="cmDataGrid" StaysOpen="True">
                    <MenuItem Name="mnuView" Header="نمایش">
                        <MenuItem Name="mnuHideColumn"  Header="Hide Column" Click="mnuHideColumn_Click"/>
                        <MenuItem Name="mnuShowColumn" Header="Show Column"/>
                        <Separator/>
                        <MenuItem Name="mnuGroupByColumn" 
                          Header="Group by this column" Click="mnuGroupColumn_Click" />
                        <MenuItem Name="mnuClearGroups" 
                          Header="Clear grouping" Click="mnuGroupColumn_Click" />
                        <Separator/>
                        <MenuItem Header="Header Alignment">
                            <MenuItem Name="mnuHeaderCenter" Header="Center"/>
                            <MenuItem Name="mnuHeaderLeft" Header="Left"/>
                            <MenuItem Name="mnuHeaderRight" Header="Right"/>
                        </MenuItem>
                        <MenuItem Header="Content Alignment">
                            <MenuItem Name="mnuContentCenter" Header="Center"/>
                            <MenuItem Name="mnuContentLeft" Header="Left"/>
                            <MenuItem Name="mnuContentRight" Header="Right"/>
                        </MenuItem>
                    </MenuItem>

                </ContextMenu>
            </my:DataGrid.ContextMenu>
        </my:DataGrid>

有什么建议吗?

0 个答案:

没有答案