none
程式無法加入任何事件 RRS feed

  • 問題

  • 

    不知道寫了多久,突然無法加入任何按鈕事件,非常的困擾,求解!?

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="500" Width="800">
        <Grid>
            <Button Content="新增成員" Height="23" Name="add" Width="75" Margin="213,85,490,353" />
            <Canvas Name="Canvas_login" Visibility="Collapsed">
                <Image Canvas.Left="207" Canvas.Top="285" Height="157" Name="image7" Stretch="Uniform" Width="444" Source="/WpfApplication1;component/Images/login.png" HorizontalAlignment="Left"/>
                <Image Canvas.Left="300" Canvas.Top="70" Height="180" Name="image5" Stretch="Uniform" Width="166" Source="/WpfApplication1;component/Images/log.png" />
                <TextBlock Height="23" x:Name="errormessage" Width="229" OpacityMask="Crimson" Foreground="#FFE5572C" Canvas.Left="261" Canvas.Top="381" />
                <TextBox Height="18" Name="textBox_account" Width="130" Canvas.Left="347" Canvas.Top="325" BorderThickness="0" />
                <PasswordBox Height="17" Name="passwordBox" Width="130" Canvas.Left="347" Canvas.Top="360" BorderThickness="0" />
                <Label Canvas.Left="329" Canvas.Top="403" Height="25" Name="lb_login" Width="127" MouseDown="login_MouseDown"/>
                <Label Canvas.Left="526" Canvas.Top="320" Height="28" Name="lb_start_game" Width="108" MouseDown="game_MouseDown" Visibility="Collapsed" />
                <Label Canvas.Left="526" Canvas.Top="371" Height="28" Name="lb_enter_system" Width="108" MouseDown="system_MouseDown" Visibility="Collapsed" />
                <Canvas.Background>
                    <ImageBrush ImageSource="/WpfApplication1;component/Images/History%20Of%20The%20Internet%20%28HD%29_%28720p%29.png" />
                </Canvas.Background>
            </Canvas>
            <Canvas Name="Canvas_system" Margin="0,0,12,0" Visibility="Collapsed">
                <StackPanel Canvas.Left="23" Canvas.Top="55" Height="30" Name="stackPanel1" Width="92" Orientation="Horizontal">
                    <Image Height="26" Name="image1" Stretch="Uniform" Width="28" Source="/WpfApplication1;component/Images/gameplay.png" Canvas.Top="55" />
                    <Label Height="33" Name="label1" FontFamily="Adobe Fan Heiti Std" Foreground="Black" FontSize="14" Width="75" Canvas.Top="55" />
                </StackPanel>
                <StackPanel Height="30" Name="stackPanel2" Orientation="Horizontal" Width="92" Canvas.Left="25" Canvas.Top="115">
                    <Image Height="26" Name="image12" Source="/WpfApplication1;component/Images/login1.png" Stretch="Uniform" Width="28" Canvas.Top="115" />
                    <Label FontFamily="Adobe Fan Heiti Std" FontSize="14" Foreground="Black" Height="33" Name="label2" Width="68" Canvas.Top="115" />
                </StackPanel>
                <StackPanel Height="30" Name="stackPanel3" Orientation="Horizontal" Width="92" Canvas.Left="23" Canvas.Top="175">
                    <Image Height="26" Name="image13" Source="/WpfApplication1;component/Images/register.png" Stretch="Uniform" Width="28" Canvas.Top="175" />
                    <Label FontFamily="Adobe Fan Heiti Std" FontSize="14" Foreground="Black" Height="33" Name="label3" Width="75" Canvas.Top="175" />
                </StackPanel>
                <StackPanel Height="30" Name="stackPanel4" Orientation="Horizontal" Width="92" Canvas.Left="25" Canvas.Top="235">
                    <Image Height="26" Name="image14" Source="/WpfApplication1;component/Images/logout.png" Stretch="Uniform" Width="28" Canvas.Top="235" />
                    <Label FontFamily="Adobe Fan Heiti Std" FontSize="14" Foreground="Black" Height="33" Name="label4" Width="75" Canvas.Top="235" />
                </StackPanel>
                <StackPanel Height="30" Name="stackPanel5" Orientation="Horizontal" Width="92" Canvas.Left="25" Canvas.Top="295">
                    <Image Height="26" Name="image15" Source="/WpfApplication1;component/Images/logout.png" Stretch="Uniform" Width="28" Canvas.Top="295" />
                    <Label FontFamily="Adobe Fan Heiti Std" FontSize="14" Foreground="Black" Height="33" Name="label5" Width="75" Canvas.Top="295" />
                </StackPanel>
                <StackPanel Height="30" Name="stackPanel6" Orientation="Horizontal" Width="92" Canvas.Left="25" Canvas.Top="355">
                    <Image Height="26" Name="image16" Source="/WpfApplication1;component/Images/logout.png" Stretch="Uniform" Width="28" Canvas.Top="355" Visibility="Visible" />
                    <Label FontFamily="Adobe Fan Heiti Std" FontSize="14" Foreground="Black" Height="33" Name="label6" Width="75" Canvas.Top="355" />
                </StackPanel>
                <Image Canvas.Left="0" Canvas.Top="45" Height="50" Name="img1" Source="/WpfApplication1;component/Images/ButtonA.png" Stretch="Fill" Width="149" MouseEnter="image_MouseEnter" MouseLeave="image_MouseLeave" MouseLeftButtonDown="image_MouseLeftButtonDown" MouseLeftButtonUp="image_MouseLeftButtonUp" MouseDown="image_MouseDown" Visibility="Visible" />
                <Image Canvas.Left="0" Canvas.Top="105" Height="50" Name="img2" Source="/WpfApplication1;component/Images/ButtonA.png" Stretch="Fill" Width="149" MouseEnter="image_MouseEnter" MouseLeave="image_MouseLeave" MouseLeftButtonDown="image_MouseLeftButtonDown" MouseLeftButtonUp="image_MouseLeftButtonUp" MouseDown="image_MouseDown" />
                <Image Canvas.Left="0" Canvas.Top="165" Height="50" Name="img3" Source="/WpfApplication1;component/Images/ButtonA.png" Stretch="Fill" Width="149" MouseEnter="image_MouseEnter" MouseLeave="image_MouseLeave" MouseLeftButtonDown="image_MouseLeftButtonDown" MouseLeftButtonUp="image_MouseLeftButtonUp" MouseDown="image_MouseDown" />
                <Image Canvas.Left="0" Canvas.Top="225" Height="50" Name="img4" Source="/WpfApplication1;component/Images/ButtonA.png" Stretch="Fill" Width="149" MouseEnter="image_MouseEnter" MouseLeave="image_MouseLeave" MouseLeftButtonDown="image_MouseLeftButtonDown" MouseLeftButtonUp="image_MouseLeftButtonUp" MouseDown="image_MouseDown" />
                <Image Canvas.Left="0" Canvas.Top="285" Height="50" Name="img5" Source="/WpfApplication1;component/Images/ButtonA.png" Stretch="Fill" Width="149" MouseEnter="image_MouseEnter" MouseLeave="image_MouseLeave" MouseLeftButtonDown="image_MouseLeftButtonDown" MouseLeftButtonUp="image_MouseLeftButtonUp" MouseDown="image_MouseDown" />
                <Image Canvas.Left="0" Canvas.Top="345" Height="50" Name="img6" Source="/WpfApplication1;component/Images/ButtonA.png" Stretch="Fill" Width="149" MouseEnter="image_MouseEnter" MouseLeave="image_MouseLeave" MouseLeftButtonDown="image_MouseLeftButtonDown" MouseLeftButtonUp="image_MouseLeftButtonUp" MouseDown="image_MouseDown" />
                <Canvas.Background>
                    <ImageBrush ImageSource="/WpfApplication1;component/Images/History%20Of%20The%20Internet%20%28HD%29_%28720p%29.png" />
                </Canvas.Background>
            </Canvas>
            <Canvas Height="350" Name="canvas_personal" Width="546" Background="#114250A9" Visibility="Collapsed" Margin="180,55,50,55">
                <Grid Canvas.Left="31" Canvas.Top="26" Height="146" Name="grid1" Width="193">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80" />
                        <ColumnDefinition Width="226" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="29" />
                        <RowDefinition Height="29" />
                        <RowDefinition Height="29" />
                        <RowDefinition Height="29" />
                        <RowDefinition Height="29" />
                    </Grid.RowDefinitions>
                    <Label Content="姓名:" Height="26" Margin="2,0,1,1" />
                    <Label Content="性別:" Height="26" Margin="2,0,1,1" Grid.Row="1" />
                    <Label Content="年齡:" Height="26" Margin="2,0,1,1" Grid.Row="2" />
                    <Label Content="出生年月日:" Height="26" Margin="2,0,1,1" Grid.Row="3" />
                    <Label Content="主治醫生:" Height="26" Margin="2,0,1,1" Grid.Row="4" />
                    <Label Content="name" Height="28" Name="lbname_p" Grid.Column="1" Margin="0,0,0,0" Grid.Row="0" />
                    <Label Content="sex" Height="28" Name="lbsex_p" Grid.Column="1" Margin="0,0,0,0" Grid.Row="1" />
                    <Label Content="age" Height="28" Name="lbage_p" Grid.Column="1" Margin="0,0,0,0" Grid.Row="2" />
                    <Label Content="birth" Height="28" Name="lbbirth_p" Grid.Column="1" Margin="0,0,0,0" Grid.Row="3" />
                    <Label Content="physician" Height="28" Name="lbphysician_p" Grid.Column="1" Margin="0,0,0,0" Grid.Row="4" />
                </Grid>
            </Canvas>
            <Canvas Height="350" Name="canvas_management" Width="546" Background="#114250A9" Visibility="Visible" Margin="180,55,50,55">
                <Grid Canvas.Left="300" Canvas.Top="70" Height="210" Name="grid_m" Width="180" Visibility="Collapsed">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="85" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="8*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                        <RowDefinition Height="30" />
                        <RowDefinition Height="30" />
                        <RowDefinition Height="30" />
                        <RowDefinition Height="30" />
                        <RowDefinition Height="30" />
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
                    <Label Content="姓名:" Height="26" Margin="2,0,1,1" />
                    <Label Content="性別:" Height="26" Margin="2,0,1,1" Grid.Row="1" />
                    <Label Content="年齡:" Height="26" Margin="2,0,1,1" Grid.Row="2" />
                    <Label Content="出生年月日:" Height="26" Margin="2,0,1,1" Grid.Row="3" />
                    <Label Content="E-mail:" Height="26" Margin="2,0,1,1" Grid.Row="4" />
                    <Label Content="主治醫生:" Height="26" Margin="2,0,1,1" Grid.Row="5" />
                    <Label Content="name" Height="28" Name="lbname_m" Grid.Column="1" Margin="0,0,0,0" Grid.Row="0" />
                    <Label Content="sex" Height="28" Name="lbsex_m" Grid.Column="1" Margin="0,0,0,0" Grid.Row="1" />
                    <Label Content="age" Height="28" Name="lbage_m" Grid.Column="1" Margin="0,0,0,0" Grid.Row="2" />
                    <Label Content="birth" Height="28" Name="lbbirth_m" Grid.Column="1" Margin="0,0,0,0" Grid.Row="3" />
                    <Label Content="email" Name="lbemail_m" Grid.Column="1" Margin="0,0,0,0" Grid.Row="4" />
                    <Label Content="physician" Name="lbphysician_m" Grid.Column="1" Margin="0,0,0,0" Grid.Row="5" />                
                </Grid>
                <ListBox Canvas.Left="20" Canvas.Top="110" Height="219" Name="listBox_d" Width="100" />
                <ListBox Canvas.Left="141" Canvas.Top="110" Height="219" Name="listBox_p" Width="100" />
                <Label Canvas.Left="46" Canvas.Top="77" Content="醫生" Height="25" Width="40" />
                <Label Canvas.Left="171" Canvas.Top="77" Content="病患" Height="25" Width="40" />
            </Canvas>
            
            <Button Content="刪除成員" Height="23" Name="delete" Width="75" Margin="333,85,370,353" />
            
            <Button  Content="修改資料" Height="23" HorizontalAlignment="Left" Margin="600,355,0,0" Name="modify" VerticalAlignment="Top" Width="75" />
        </Grid>
    </Window>
    

    2013年3月7日 下午 02:47

解答

  • 錯誤訊息不是說了嗎 MainWindow 必須是檔案中的第一個 class

    開啟你的MainWindow.xaml.cs 調整 class 區塊的位置

    讓他變成類似:

    namespace WpfApplication1
    {
        /// <summary>
        /// MainWindow.xaml 的互動邏輯
        /// </summary>
        public partial class MainWindow : Window
        {
                //略
        }
                //略
    }


    以下為簽名檔,如果你愛拉椅子坐那就是你的問題。
    先查MSDN文件庫
    再用GOOGLE搜尋
    才到論壇來發問

    這是論壇不是技術支援中心
    沒有人得無償解答你的問題

    在標題或文章註明很急
    不會增加網友回覆速度

    • 已標示為解答 Donzer 2013年3月9日 上午 05:17
    2013年3月7日 下午 04:07

所有回覆

  • 錯誤訊息不是說了嗎 MainWindow 必須是檔案中的第一個 class

    開啟你的MainWindow.xaml.cs 調整 class 區塊的位置

    讓他變成類似:

    namespace WpfApplication1
    {
        /// <summary>
        /// MainWindow.xaml 的互動邏輯
        /// </summary>
        public partial class MainWindow : Window
        {
                //略
        }
                //略
    }


    以下為簽名檔,如果你愛拉椅子坐那就是你的問題。
    先查MSDN文件庫
    再用GOOGLE搜尋
    才到論壇來發問

    這是論壇不是技術支援中心
    沒有人得無償解答你的問題

    在標題或文章註明很急
    不會增加網友回覆速度

    • 已標示為解答 Donzer 2013年3月9日 上午 05:17
    2013年3月7日 下午 04:07
  • 非常感謝~
    我一直以為是我的物件位置的問題,結果是cs檔裡面順序錯誤
    把兩個class交換順序就好了:)
    這是c#才會有的問題嗎?之前寫java視窗一樣的寫法不會這樣
    2013年3月9日 上午 05:19