1

我一直在开发一个 Windows Phone 应用程序,该应用程序将图像和文本放在一起并将它们上传到服务器。

调试应用程序时出现问题。这个问题似乎是技术性的。我真的不知道该怎么做。

这就是为什么我想在这里发布这个问题。如果你们中的某个人可以帮助解决这个问题,我将非常感谢这里提供给我的帮助。

我非常感谢这里所做的工作。没有你们,我们真的不会走到这一步。您让我们有机会从错误中吸取教训。

再次感谢。

请检查我的代码是否需要任何调整。

这是我在模拟器上调试时弹出的错误消息:

未能分配给属性“System.Windows.Controls.Primitives.ButtonBase.Click”。[行:41 位置:250]

这是我的第一篇文章,所以我不能发布图片,很遗憾。

我很欣赏这里所做的工作。

   private void button3_Click(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)

       //void photoChooserTask_Completed(object sender, PhotoResult e)
        //{

            {
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                image1.Source = bmp;
                byte[] sbytedata = ReadToEnd(e.ChosenPhoto);
                string s = sbytedata.ToString();
                WebClient wc = new WebClient();
                Uri u = new Uri("ftp://ftp.icupload.cs201.com/icupload.cs201.com/images/");
                wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
                wc.OpenWriteAsync(u, "POST", sbytedata);

            }
        }
        public static void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                object[] objArr = e.UserState as object[];
                byte[] fileContent = e.UserState as byte[];

                Stream outputStream = e.Result;
                outputStream.Write(fileContent, 0, fileContent.Length);
                outputStream.Flush();
                outputStream.Close();
                string s = e.Result.ToString(); ;

            }
        }
        public static byte[] ReadToEnd(System.IO.Stream stream)
        {
            long originalPosition = stream.Position;
            stream.Position = 0;

            try
            {
                byte[] readBuffer = new byte[4096];

                int totalBytesRead = 0;
                int bytesRead;

                while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
                {
                    totalBytesRead += bytesRead;

                    if (totalBytesRead == readBuffer.Length)
                    {
                        int nextByte = stream.ReadByte();
                        if (nextByte != -1)
                        {
                            byte[] temp = new byte[readBuffer.Length * 2];
                            Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
                            Buffer.SetByte(temp, totalBytesRead, (byte)nextByte);
                            readBuffer = temp;
                            totalBytesRead++;
                        }
                    }
                }

                byte[] buffer = readBuffer;
                if (readBuffer.Length != totalBytesRead)
                {
                    buffer = new byte[totalBytesRead];
                    Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
                }
                return buffer;
            }
            finally
            {
                stream.Position = originalPosition;
            }    

    }

这是第 41 行...位置 252 是“Click = myButton3_Click”

<Button BorderBrush="#FFFF7300" Content="Capture Photo" FontSize="22" Foreground="#FFFF7300" Height="78" Margin="263,23,-10,0" Name="myButton" VerticalAlignment="Top" Click="button2_Click" FontFamily="Tahoma" BorderThickness="4" />
        <Image Height="275" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="269" />
        <Button Content="Comment &amp; Location" Height="72" HorizontalAlignment="Left" Margin="92,599,0,0" Name="button1" VerticalAlignment="Top" Width="294" Foreground="#FFFF7300" OpacityMask="#FFFF7300" BorderBrush="#FF091A08" FontFamily="Tahoma" FontWeight="Normal" Background="Transparent" Click="button1_Click" />
        <Button Content="Select Photo" HorizontalAlignment="Left" Margin="264,107,0,0" Name="button2" Width="202" FontSize="24" Foreground="#FFFF7300" FontFamily="Tahoma" Background="Transparent" BorderBrush="#FFFF7300" BorderThickness="4" Height="78" VerticalAlignment="Top" Click="button2_Click_1" />
        <Button Content="Upload" Height="84" HorizontalAlignment="Left" Margin="272,191,0,0" Name="myButton3" VerticalAlignment="Top" Width="186" BorderBrush="#FFFF7300" BorderThickness="4" FontFamily="Tahoma" FontSize="26" Foreground="#FFFF7300" Click="myButton3_Click" ClickMode="Release" DataContext="{Binding}" />
        <TextBlock Height="200" HorizontalAlignment="Left" Margin="28,290,0,0" Name="textBlock1" Text="" VerticalAlignment="Top" Width="400" FontSize="30" TextTrimming="WordEllipsis" TextWrapping="Wrap" />

在您在这里提到的所有更改之后,我仍然得到三个相同的错误。

错误 2“System.Windows.RoutedEventArgs”不包含“ChosenPhoto”的定义,并且找不到接受“System.Windows.RoutedEventArgs”类型的第一个参数的扩展方法“ChosenPhoto”(您是否缺少 using 指令或程序集参考?) C:\Users\Yaseen\Desktop\IC Final\Phone Application\MainPage.xaml.cs 107 41 Phone Application

这些直接出现在 button3 语法之后

4

2 回答 2

2

我认为您发布的代码与错误消息无关。

但是您的问题似乎与

这里

和这里

于 2012-05-11T10:41:22.693 回答
1

myButton3_Click代码隐藏只有button3_Click.

这些应该是匹配的。

于 2012-05-11T19:21:25.190 回答