2012-08-03 50 views
1

我正在開發silverlight應用程序。我正在使用silverlight中的itemscontrol來根據需求來插入UI。如何調用ItemsControls上的按鈕點擊子窗口?

<ItemsControl x:Name="CertificationsAndLicensesItemsControl"> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"></RowDefinition>        
         </Grid.RowDefinitions> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="Auto"></ColumnDefinition> 
         </Grid.ColumnDefinitions> 

         <Grid Grid.Row="0"> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="Auto"></RowDefinition> 
           <RowDefinition Height="Auto"></RowDefinition> 
          </Grid.RowDefinitions> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="Auto"></ColumnDefinition> 
           <ColumnDefinition Width="Auto"></ColumnDefinition> 
          </Grid.ColumnDefinitions> 
          <Grid Grid.Row="0" Grid.Column="0" Width="500"> 
           <TextBlock TextWrapping="Wrap" Foreground="Green" Text="{Binding Path=CertificationsAndLicensesTitle}" FontWeight="Bold" Margin="5"></TextBlock> 
          </Grid> 
          <Grid Grid.Row="0" Grid.Column="1"> 
           <StackPanel Orientation="Horizontal"> 
            <TextBlock FontWeight="Bold" Text="Valid from:" HorizontalAlignment="Left" Margin="5"></TextBlock> 
            <TextBlock Text="{Binding Path=ValidFrom}" Margin="5" ></TextBlock> 
            <TextBlock Text="Until" Margin="5"></TextBlock> 
            <TextBlock Text="{Binding Until}" Margin="5"></TextBlock> 
           </StackPanel> 
          </Grid> 
          <Grid Grid.Row="1" Grid.ColumnSpan="2"> 
           <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5"> 
            <Button x:Name="EditButton" Tag="{Binding Path=ID}" Content="Edit" Click="EditButton_Click"></Button> 
            <Button x:Name="DeleteButton" Tag="{Binding Path=ID}" Content="Delete" Click="DeleteButton_Click"></Button> 
           </StackPanel> 
          </Grid> 
         </Grid> 

        </Grid> 

       </DataTemplate> 

      </ItemsControl.ItemTemplate> 
     </ItemsControl> 

後面的代碼如下所示

private void EditButton_Click(object sender, RoutedEventArgs e) 
     { 
      //int a = 10; 
      //CertificationsAndLicensesChildWindow obj = new CertificationsAndLicensesChildWindow(); 
      //obj.Show(); 
      ChildWindow1 obj1 = new ChildWindow1(); 
      obj1.Show(); 
     } 

     private void DeleteButton_Click(object sender, RoutedEventArgs e) 
     { 
      CertificationsAndLicensesChildWindow obj = new CertificationsAndLicensesChildWindow(); 
      obj.Show(); 
     } 

犯規得到顯示按鈕,點擊子窗口。點擊按鈕後,整個UI將消失。如果我刪除以下句子

ChildWindow1 obj1 = new ChildWindow1(); 
       obj1.Show(); 

然後至少得到斷點。如果我保留上述判斷,斷點不會受到影響。如何shuld我按鈕點擊顯示子窗口?能否請您給我提供任何代碼或鏈接,通過它我可以解決上述問題

回答

0

消失的UI幾乎總是意味着未處理的異常 - propably有ChildWindow1創建/顯示過程中的一些錯誤。如果未附加處理程序(在App構造函數中執行),則可以嘗試在App類中爲未處理的異常附加處理程序,並在未處理的異常處理程序中設置斷點。這應該可以幫助您追蹤導致UI缺失的異常情況。

默認情況下,創建Silverlight項目時,有一個地方投手並報告例外DOM - 你應該能夠看到例外JavaScript控制檯。

+0

是。你是對的。我已經把斷點Application_UnhandledException在App.xaml.cs,發現它是給錯誤無法加載程序集System.Windows.Controls。解決了這個錯誤。一切都在工作文件。非常感謝 – 2012-08-03 13:59:09

相關問題