2013-02-20 47 views
0

我在將事件處理程序添加到Windows Phone 8的XAML中的AutoCompleteBox時遇到了問題。它之前很有用,但是因爲我移動了它的東西不再有效。以下是我的MainPage.xaml中的摘錄:在XAML中添加事件處理程序時出現XamlParseException

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
     <Grid Margin="0,0,0,407"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="50"/> 
       <RowDefinition Height="70"/> 
       <RowDefinition Height="50"/> 
       <RowDefinition Height="70"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="2*"/> 
       <ColumnDefinition Width="3*"/> 
      </Grid.ColumnDefinitions> 

      <TextBlock Text="Start:" FontSize="35"/> 
      <toolkit:AutoCompleteBox Grid.Row="1" x:Name="autoStadtStart" ItemsSource="{Binding Towns}" Text="Stadt" Tap="AutoCompleteBox_Click" LostFocus="AutoCB_Town_Reset"/> 
      <toolkit:AutoCompleteBox Grid.Row="1" Grid.Column="1" x:Name="autoBusStopStart" ItemsSource="{Binding BusStops}" Margin="1,0,-1,0" Text="Haltestelle" Tap="AutoCompleteBox_Click" LostFocus="AutoCB_BusStop_Reset"/> 

      <TextBlock Grid.Row="2" Text="Ziel:" FontSize="35"/> 
      <toolkit:AutoCompleteBox Grid.Row="3" x:Name="autoStadtZiel" ItemsSource="{Binding Towns}" Text="Stadt" Tap="AutoCompleteBox_Click" LostFocus="AutoCB_Town_Reset"/> 
      <toolkit:AutoCompleteBox Grid.Row="3" Grid.Column="1" x:Name="autoBusStopZiel" ItemsSource="{Binding BusStops}" Margin="1,0,-1,0" Text="Haltestelle" Tap="AutoCompleteBox_Click" LostFocus="AutoCB_BusStop_Reset"/> 

     </Grid> 
    </Grid> 

...這是MainPage.xaml.cs中相應的代碼:

private void AutoCompleteBox_Click(AutoCompleteBox sender, System.Windows.Input.GestureEventArgs e) 
    { 
     sender.Text = ""; 
    } 

    private void AutoCB_BusStop_Reset(AutoCompleteBox sender, System.Windows.Input.GestureEventArgs e) 
    { 
     if (sender.Text.Equals("")) 
      sender.Text = "Haltestelle"; 
    } 

    private void AutoCB_Town_Reset(AutoCompleteBox sender, System.Windows.Input.GestureEventArgs e) 
    { 
     if (sender.Text.Equals("")) 
      sender.Text = "Stadt"; 
    } 

當我刪除點擊=」 ... 「和LostFocus」...「從AutoCompleteBox控件中,異常不會拋出。有沒有人有一個想法是怎麼回事?

回答

1

您方法的簽名是錯誤的。它應該是:

private void AutoCompleteBox_Click(object sender, System.Windows.Input.GestureEventArgs e) 

private void AutoCB_BusStop_Reset(object sender, System.Windows.RoutedEventArgs e) 

private void AutoCB_Town_Reset(object sender, System.Windows.RoutedEventArgs e) 
+0

我改變了它,但我仍然得到相同的異常... – user2035039 2013-02-20 19:53:11

相關問題