在ChildWindow中加载事件后,Silverlight DataGrid为null

时间:2012-06-14 20:33:27

标签: silverlight xaml

这是XAML结构。您将在下面看到我正在订阅网格的Loaded事件。但是当偶数点火时,this.selectionGrid仍然是null - 即使在后续的布局更新中,它仍然是null,即使我可以看到所有网格都已填充。

我确实使用了MEFedMVVM和MvvmLight,但我看不出它与这种情况有什么关系。

任何想法为什么?

<Grid x:Name="LayoutRoot" Margin="2">
    <toolkit:BusyIndicator IsBusy="{Binding IsBusy}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ContentPresenter
                    Visibility="{Binding Path=CurrentStep,Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=1}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock Text="Select Equipment" Style="{StaticResource HeaderBlockStyle}" /> 
                    <ScrollViewer Grid.Row="1">
                        <sdk:DataGrid x:Name="selectionGrid" GridLinesVisibility="All" AlternatingRowBackground="White" ItemsSource="{Binding Path=AvailableEquipmentView}" AreRowDetailsFrozen="True" 
                                AutoGenerateColumns="False" SelectionMode="Extended" RowDetailsVisibilityMode="Visible" LayoutUpdated="selectionGrid_LayoutUpdated" Loaded="selectionGrid_Loaded" LoadingRowGroup="selectionGrid_LoadingRowGroup">

1 个答案:

答案 0 :(得分:1)

您应该删除ContentPresenter。 ContentPresenter旨在显示其内容属性,而不是“手动”子项。

我还要提到您不需要将控件放入BusyIndi​​cator。 BusyIndi​​cator将填充所有可用空间,因此将其放置在网格的“底部”(在xaml中的所有其他控件下方)

<Grid x:Name="LayoutRoot" Margin="2">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid Visibility="{Binding Path=CurrentStep,Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=1}">
        <Grid.RowDefinitions>
             <RowDefinition Height="Auto" />
              <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock Text="Select Equipment" Style="{StaticResource HeaderBlockStyle}" /> 
        <ScrollViewer Grid.Row="1">
            <sdk:DataGrid x:Name="selectionGrid" GridLinesVisibility="All" AlternatingRowBackground="White" 
                          ItemsSource="{Binding Path=AvailableEquipmentView}" AreRowDetailsFrozen="True" 
                          AutoGenerateColumns="False" SelectionMode="Extended" RowDetailsVisibilityMode="Visible" 
                          LayoutUpdated="selectionGrid_LayoutUpdated" Loaded="selectionGrid_Loaded" 
                          LoadingRowGroup="selectionGrid_LoadingRowGroup">
    <! -- Other controls -->
    <toolkit:BusyIndicator IsBusy="{Binding IsBusy}">
</Grid>