在XAML中添加事件处理程序时,XamlParseException [英] XamlParseException when adding event handler in XAML
问题描述
在Windows Phone 8的XAML中,将事件处理程序添加到AutoCompleteBox中,遇到麻烦。以前工作过,但是由于我已经移动了它,所以不再。以下是MainPage.xaml的摘录:
< Grid x:Name =ContentPanelGrid.Row = 1保证金=12,0,12,0>
<网格边距=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 =开始:FontSize =35/>
< toolkit:AutoCompleteBox Grid.Row =1x:Name =autoStadtStartItemsSource ={Binding Towns}Text =StadtTap =AutoCompleteBox_ClickLostFocus =AutoCB_Town_Reset/>
< toolkit:AutoCompleteBox Grid.Row =1Grid.Column =1x:Name =autoBusStopStartItemsSource ={Binding BusStops}Margin =1,0,-1,0 Text =HaltestelleTap =AutoCompleteBox_ClickLostFocus =AutoCB_BusStop_Reset/>
< TextBlock Grid.Row =2Text =Ziel:FontSize =35/>
< toolkit:AutoCompleteBox Grid.Row =3x:Name =autoStadtZielItemsSource ={Binding Towns}Text =StadtTap =AutoCompleteBox_ClickLostFocus =AutoCB_Town_Reset/>
< toolkit:AutoCompleteBox Grid.Row =3Grid.Column =1x:Name =autoBusStopZielItemsSource ={Binding BusStops}Margin =1,0,-1,0 Text =HaltestelleTap =AutoCompleteBox_ClickLostFocus =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;
}
当我删除Tap =...和LostFocus... 从AutoCompleteBox控件,异常不会抛出。有没有人知道发生了什么?
你的方法的签名是错误的。它应该是:
private void AutoCompleteBox_Click(object sender,System.Windows.Input.GestureEventArgs e)
/ pre>
private void AutoCB_BusStop_Reset(object sender,System.Windows.RoutedEventArgs e)
private void AutoCB_Town_Reset(object sender,System.Windows.RoutedEventArgs e)
I am having trouble adding event handlers to an AutoCompleteBox in XAML for windows phone 8. It worked before, but since I moved things around it doesn't anymore. The following is an extract from my MainPage.xaml:
<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>
... and this is the corresponding code in 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"; }
When I remove Tap="..." and LostFocus"..." from the AutoCompleteBox controls, the exception is not thrown. Does anyone have an idea what is going on?
解决方案The signatures of your methods are wrong. It should be:
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)
这篇关于在XAML中添加事件处理程序时,XamlParseException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!