2012-06-14 20 views
0

這裏是XAML結構。您會在下面看到我正在訂閱網格的Loaded事件。但是,即使發生火災,this.selectionGrid仍然是null - 即使在隨後的佈局更新中,它仍然是null,即使我可以看到網格全部填充。在ChildWindow中加載事件後,Silverlight DataGrid爲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"> 
+0

的問題:你是否缺少一些XAML?爲什麼BusyIndi​​cator內的內容?爲什麼在ContentPresenter中定義內容 –

+0

是的,我的XAML非常龐大 - 我只想給出一個結構感。將控件放在BusyIndi​​cator中是我經常做的事情,當您設置IsBusy時,所有的子控件都被禁用 - 這有所幫助。它在一個ContentPresenter中,因爲我有幾個不同的視圖,我將在嚮導類型場景中提出,因爲您可能會在那裏觀察可見性綁定。 –

+0

BusyIndi​​cator的標準行爲是「禁用」項目。只需將它放在xaml的末尾,不需要在其中放入項目。看到我對這個問題的回答http://stackoverflow.com/questions/9012870/silverlight-busyindicator/9014486#9014486。這不是ContentPresenter打算使用的方式。它們旨在呈現來自其內容屬性的內容。 –

回答

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> 
相關問題