繁体   English   中英

编辑现有WP8项目时出错

[英]Errors when editting existing WP8 project

所以我只是从这些东西开始,并陷入了一些冲突。 我有一个枢轴音板应用程序,我需要将其更改为一系列全景图页面,但具有相同的功能。

我已经适当地完成了所有的xaml和c#,但是我认为因为必须创建一个新的MainPage并删除较旧的MainPage,所以我创建了多个错误。 我怀疑它们都有类似的原因,所以我只提供三个。

错误1类型'SoundBoard.MainPage'已经包含'LayoutRoot'\\ SoundBoard \\ obj \\ Debug \\ Cartoons.g.cs的定义

错误30在当前上下文\\ SoundBoard \\ Cartoons.xaml.cs中不存在名称“ AudioPlayer”

错误7类型'SoundBoard.MainPage'已经定义了一个名为'InitializeComponent'的成员,具有相同的参数类型\\ SoundBoard \\ obj \\ Debug \\ Cartoons.g.cs

我将链接当前的MainPage和Cartoons,希望你们能帮助我。

MainPage.xaml中:

<phone:PhoneApplicationPage
    x:Class="SoundBoard.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DataContext="{d:DesignData SampleData/SampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="SoundBoard" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="Categories" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Warnings" HorizontalAlignment="Left" Margin="244,304,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click_3"/>
            <Button Content="Taunts" HorizontalAlignment="Left" Margin="27,304,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click_2"/>
            <Button Content="Cartoons" HorizontalAlignment="Left" Margin="244,123,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click_1"/>
            <Button Content="Animals" HorizontalAlignment="Left" Margin="27,123,0,0" VerticalAlignment="Top" Height="160" Width="182" Background="Red" Click="Button_Click"/>

        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

MainPage.xaml.cs中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace SoundBoard
{
    public partial class FirstPage : PhoneApplicationPage
    {
        public FirstPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Animals.xaml", UriKind.Relative));
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Cartoons.xaml", UriKind.Relative));
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Taunts.xaml", UriKind.Relative));
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Warnings.xaml", UriKind.Relative));
        }
    }
}

Cartoons.xaml:

<phone:PhoneApplicationPage
    x:Class="SoundBoard.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DataContext="{d:DesignData SampleData/SampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">


    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot">
        <phone:Panorama Title="{Binding Path=LocalizedResources.ApplicationTitle,
            Source={StaticResource LocalizedStrings}}">

            <!--Panorama item one-->
            <phone:PanoramaItem Header="Cartoons">
                <Grid>
                    <Image HorizontalAlignment="Center" Height="431" Margin="10,10,0,0" VerticalAlignment="Top" Width="400" Source="/Assets/cartoon.jpg"/>
                </Grid>
            </phone:PanoramaItem>

            <!--Panorama item two-->
            <phone:PanoramaItem Header="Sounds">
                <phone:LongListSelector
                    Margin="0,0,-12,0" 
                    ItemsSource="{Binding Cartoons.Items}"
                    LayoutMode="Grid"
                    GridCellSize="150,150"                  
                    >
                    <phone:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <Grid Background="{StaticResource PhoneAccentBrush}">

                                <Grid VerticalAlignment="Top" HorizontalAlignment="Right" 
                                      Width="40" Height="40" Margin="0,6,6,0">
                                    <Ellipse Stroke="{StaticResource PhoneForegroundBrush}" 
                                             StrokeThickness="3" />
                                    <Image Source="Assets/AppBar/Play.png" />


                                </Grid>

                                <StackPanel VerticalAlignment="Bottom">
                                    <TextBlock Text="{Binding Title}"
                                               Margin="6,0,0,6"/>

                                </StackPanel>

                            </Grid>

                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>
            </phone:PanoramaItem>

            <!--Panorama item three-->
            <phone:PanoramaItem Header="Record">
                <Grid>
                    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                        <MediaElement x:Name="AudioPlayer" AutoPlay="False" />

                        <StackPanel>
                            <ToggleButton Content="Record"
                                          Checked="RecordAudioChecked"
                                          Unchecked="RecordAudioUnchecked"/>
                            <Grid Width="200" 
                                  Height="200" 
                                  Name="ReelGrid"
                                  RenderTransformOrigin=".5,.5">
                                <Grid.RenderTransform>
                                    <CompositeTransform />
                                </Grid.RenderTransform>


                                <Ellipse Fill="{StaticResource PhoneAccentBrush}" />

                                <Ellipse Height="20"
                                         Width="20"
                                         Fill="{StaticResource PhoneForegroundBrush}" />
                                <Rectangle Height="20"
                                           Width="20"
                                           Margin="0,20,0,20"
                                           VerticalAlignment="Top" 
                                           Fill="{StaticResource PhoneForegroundBrush}" />

                                <Rectangle Height="20"
                                           Width="20"
                                           Margin="0,20,0,20"
                                           VerticalAlignment="Bottom" 
                                           Fill="{StaticResource PhoneForegroundBrush}" />

                                <Rectangle Height="20"
                                           Width="20"
                                           Margin="0,0,20,0"
                                           HorizontalAlignment="Right" 
                                           Fill="{StaticResource PhoneForegroundBrush}" />

                                <Rectangle Height="20"
                                           Width="20"
                                           Margin="20,0,0,0"
                                           HorizontalAlignment="Left" 
                                           Fill="{StaticResource PhoneForegroundBrush}" />

                            </Grid>
                            <Button Name="PlayAudio" Content="Play" Click="PlayAudioClick" />
                        </StackPanel>
                    </Grid>
                </Grid>
            </phone:PanoramaItem>

        </phone:Panorama>
    </Grid>

</phone:PhoneApplicationPage>

Cartoons.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SoundBoard.Resources;
using Coding4Fun.Toolkit.Audio;
using Coding4Fun.Toolkit.Audio.Helpers;
using System.IO;
using System.IO.IsolatedStorage;
using Coding4Fun.Toolkit.Controls;
using SoundBoard.ViewModels;
using Newtonsoft.Json;

namespace SoundBoard
{
    public partial class Cartoons : PhoneApplicationPage
    {
        private MicrophoneRecorder _recorder = new MicrophoneRecorder();
        private IsolatedStorageFileStream _audioStream;
        private string _tempFileName = "tempWav.wav";

        public Cartoons()
        {
            InitializeComponent();

            DataContext = App.ViewModel;

            BuildLocalizedApplicationBar();
        }
            // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
        }

        private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LongListSelector selector = sender as LongListSelector;

            // verifying our sender is actually a LongListSelector
            if (selector == null)
                return;

            SoundData data = selector.SelectedItem as SoundData;

            // verifying our sender is actually SoundData
            if (data == null)
                return;

            if (File.Exists(data.FilePath))
            {
                AudioPlayer.Source = new Uri(data.FilePath, UriKind.RelativeOrAbsolute);
            }
            else
            {
                using (var storageFolder = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (var stream = new IsolatedStorageFileStream(data.FilePath, FileMode.Open, storageFolder))
                    {
                        AudioPlayer.SetSource(stream);
                    }
                }
            }

            selector.SelectedItem = null;
        }

        private void BuildLocalizedApplicationBar()
        {
            ApplicationBar = new ApplicationBar();

            ApplicationBarIconButton recordAudioAppBar =
                new ApplicationBarIconButton();

            recordAudioAppBar.IconUri = new Uri("/Assets/AppBar/Save.png", UriKind.Relative);
            recordAudioAppBar.Text = AppResources.AppBarSave;

            recordAudioAppBar.Click += recordAudioAppBar_Click;

            ApplicationBar.Buttons.Add(recordAudioAppBar);
            ApplicationBar.IsVisible = false;

        }

        void recordAudioAppBar_Click(object sender, EventArgs e)
        {
            InputPrompt fileName = new InputPrompt();

            fileName.Message = "What should we call the sound?";

            fileName.Completed += FileNameCompleted;

            fileName.Show();

        }

        private void FileNameCompleted(object sender, PopUpEventArgs<string, PopUpResult> e)
        {
            if (e.PopUpResult == PopUpResult.Ok)
            {

                // Create a sound data object

                SoundData soundData = new SoundData();
                soundData.FilePath = string.Format("/customAudio/{0}.wav", DateTime.Now.ToFileTime());
                soundData.Title = e.Result;

                // Save the wav file into the DIR /customAudio/

                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
                    if (!isoStore.DirectoryExists("/customAudio/"))
                        isoStore.CreateDirectory("/customAudio/");

                    isoStore.MoveFile(_tempFileName, soundData.FilePath);
                }


                // Add the SoundData to App.ViewModel.CustomSounds

                App.ViewModel.CustomSounds.Items.Add(soundData);

                // Save the list of CustomSounds to isolatedStorage.ApplicationSettings

                var data = JsonConvert.SerializeObject(App.ViewModel.CustomSounds);

                IsolatedStorageSettings.ApplicationSettings[SoundModel.CustomSoundKey] = data;
                IsolatedStorageSettings.ApplicationSettings.Save();

                // We'll need to modify sound model to retrieve CustomSounds
                //from isolatedStorage.ApplicationSettings

                NavigationService.Navigate(new Uri("", UriKind.RelativeOrAbsolute));
            }
        }

        private void RecordAudioChecked(object sender, RoutedEventArgs e)
        {
            PlayAudio.IsEnabled = false;
            ApplicationBar.IsVisible = false;
            RotateCirlce.Begin();
            _recorder.Start();
        }

        private void RecordAudioUnchecked(object sender, RoutedEventArgs e)
        {
            _recorder.Stop();

            SaveTempAudio(_recorder.Buffer);

            PlayAudio.IsEnabled = true;
            ApplicationBar.IsVisible = true;
            RotateCircle.Stop();
        }

        private void SaveTempAudio(MemoryStream buffer)
        {
            //defensive...
            if (buffer == null)
                throw new ArgumentNullException("Attempting a save on empty sound buffer.");

            //Clean out hold on audioStream
            if (_audioStream != null)
            {
                AudioPlayer.Stop();
                AudioPlayer.Source = null;

                _audioStream.Dispose();
            }

            var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);

            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {

                if (isoStore.FileExists(_tempFileName))
                    isoStore.DeleteFile(_tempFileName);

                _tempFileName = string.Format("{0}.wav", DateTime.Now.ToFileTime());


                _audioStream = isoStore.CreateFile(_tempFileName);
                _audioStream.Write(bytes, 0, bytes.Length);
                //Play ...  SetSource of a mediaElement
                AudioPlayer.SetSource(_audioStream);

            }

        }

        private void PlayAudioClick(object sender, RoutedEventArgs e)
        {
            AudioPlayer.Play();
        }

    }
}

正如我说的那样,这可能有些愚蠢,但是我真的很固执,因此非常感谢任何建议。

提前致谢。

似乎所有问题都存在于自动生成的文件Cartoons.g.cs 指向非完全自动生成的文件的唯一错误是:

The name 'AudioPlayer' does not exist in the current context \SoundBoard\Cartoons.xaml.cs

在Cartoons.xaml中声明,当AudioPlayer存在时,哪个抱怨不存在。 这就是所有奇怪的错误。

我要做的第一件事是清理(从Visual Studio中,或手动删除bindebug文件夹)并重建项目,甚至重新启动Visual Studio。 这些步骤通常可以修复奇怪的错误。

问题在于, Cartoons.xamlMainPage.xaml都具有同一行x:Class="SoundBoard.MainPage" 我不确定,但认为Cartoons.xaml对于x:Class属性应该具有不同的值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM