Reputation: 373
I got a strange error in my XAML. I added a combobox with the designer on WPF. I gave this combobox 2 items, with the designer. How do I fix this? The combobox is called: cb_gender. The items: Male and Female
XAML:
<Window xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" x:Class="HotelWPFGoedeVersie.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HotelWPFGoedeVersie"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid Name="grid_mainwindow" HorizontalAlignment="Left" Height="321" Margin="0,0,0,-0.2" VerticalAlignment="Top" Width="518">
<Grid Name="grid_logo" HorizontalAlignment="Left" Height="80" Margin="377,0,0,0" VerticalAlignment="Top" Width="141">
<Border BorderThickness="1">
<Ellipse Fill="#00FF00" HorizontalAlignment="Left" Height="79" Stroke="Black" VerticalAlignment="Top" Width="90" Margin="29.2,0.2,0,-0.8"/>
</Border>
</Grid>
<Line Fill="#FF0000" Name="redline" Stroke="Black" StrokeThickness="4" X1="0" X2="133.6" Y1="70" Y2="70" Margin="385,-29,0,259" />
<GroupBox x:Name="gb_newreservation" Header="New Reservation" HorizontalAlignment="Left" Height="263" Margin="19,10,0,0" VerticalAlignment="Top" Width="311">
<Grid Name ="grid_reservation" HorizontalAlignment="Left" Height="225" Margin="10,10,0,0" VerticalAlignment="Top" Width="282">
<Label x:Name="lbl_name" Content="Name:" HorizontalAlignment="Left" Margin="0,19,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.443,-0.789"/>
<TextBox x:Name="tb_name" HorizontalAlignment="Left" Height="23" Margin="121,23,0,0" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top" Width="120"/>
<Label x:Name="lbl_address" Content="Address:" HorizontalAlignment="Left" Margin="0,58,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="tb_address" HorizontalAlignment="Left" Height="22" Margin="121,62,0,0" TextWrapping="Wrap" Text="Address" VerticalAlignment="Top" Width="120"/>
<Label x:Name="lbl_room" Content="Room:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,147,0,0"/>
<Label x:Name="lbl_date" Content="Date:" HorizontalAlignment="Left" Margin="0,190,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.193,-0.07"/>
<DatePicker Name="dp_date" HorizontalAlignment="Left" Margin="121,192,0,0" VerticalAlignment="Top" FirstDayOfWeek="Monday" Width="120"/>
<ComboBox x:Name="cb_room" HorizontalAlignment="Left" Margin="121,150,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0" IsEditable="True"/>
<Label x:Name="lbl_gender" Content="Gender:" HorizontalAlignment="Left" Margin="0,89,0,0" VerticalAlignment="Top"/>
<ComboBox x:Name="cb_gender" HorizontalAlignment="Left" Margin="121,92,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0" IsEditable="True">
<ComboBoxItem Content="Male" HorizontalAlignment="Left" Width="118.4" />
<ComboBoxItem Content="Female" HorizontalAlignment="Left" Width="118.4"/>
</ComboBox>
<DatePicker Name="dp_birthday" HorizontalAlignment="Left" Margin="121,121,0,0" VerticalAlignment="Top" Width="120"/>
<Label x:Name="lbl_birthday" Content="Day of Birth: " HorizontalAlignment="Left" Margin="0,121,0,0" VerticalAlignment="Top"/>
</Grid>
</GroupBox>
<Button x:Name="btn_addreservation" Content="Add Reservation" HorizontalAlignment="Left" Margin="19,278,0,0" VerticalAlignment="Top" Width="103" Height="26" Click="btn_addreservation_Click"/>
<Button x:Name="btn_deletereservation" Content="Delete Reservation" HorizontalAlignment="Left" Margin="218,278,0,0" VerticalAlignment="Top" Width="103" Height="26"/>
</Grid>
</Grid>
</Window>
and this is the error:
Error CS1061 'MainWindow' does not contain a definition for >'ComboBoxItem_Selected' and no extension method 'ComboBoxItem_Selected' >accepting a first argument of type 'MainWindow' could be found (are you missing >a using directive or an assembly reference?)
Upvotes: 1
Views: 517
Reputation: 4064
First Checkup
Take a look at property window on your ComboBoxItem
Error CS1061 'MainWindow' does not contain a definition for 'ComboBoxItem_Selected' and no extension method 'ComboBoxItem_Selected' >accepting a first argument of type 'MainWindow' could be found (are you missing >a using directive or an assembly reference?)
This error happens when there's no binding event. Look for the ComboBoxItem_Selected
event stub in your .cs
. Typing event name or double-click on an item of property window automatically generates the event stub with valid parameters, but you might have accidently removed it while coding.
If there's no method stub in your .cs
leave it blank like the image above. But if you have the method stub, type the exact event name into the input box.
Further checkup
If you have the event method stub in your codebehind and you correctly bound the method to the event, then it's time to take a close look at the method's parameters. Similar events in terms of user action can have totally different event argument.
For example.
// Click event
private void Click(object sender, RoutedEventArgs e) { ... }
// MouseDown event
private void MouseDown(object sender, MouseButtonEventArgs e) { ... }
// Users can fire both events above by mouse click.
the second parameter is different, way too different. Please make sure you have a valid argument for your event.
Upvotes: 1