私のXAMLで奇妙なエラーが発生しました。私はWPFのデザイナーとコンボボックスを追加しました。 私はデザイナーとこのコンボボックス2アイテムをくれました。これをどうやって解決するのですか? コンボボックスはcb_genderと呼ばれます。アイテム:男性と女性XAML ComboBox Error WPF
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>
と、これは誤りです:
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?)
サンプルコードのどこにでも 'ComboBoxItem_Selected'がないので、問題のコードを表示していません。ただし、XAMLのイベントにイベントハンドラを割り当てる場合、コードビハインドファイルにはその名前の対応するイベントハンドラが必要です。 –