1. Hello Guest, selamat datang di Forum WinPoin. Kamu bisa bertanya, berdiskusi, sharing, dan ngobrolin apapun seputar Windows, Windows Phone, PC, Gadget, atau hal seputar Teknologi lainnya. Selamat berkomunitas! ;)

Ada yang bisa bantu ane gan buat nyelesain masalah di XamlParseException

Discussion in 'Developer Corner' started by hendra07saputra, Jun 6, 2014.

  1. hendra07saputra

    hendra07saputra New Member

    Joined:
    Apr 4, 2014
    Messages:
    12
    Selamat malam para suhu-suhu disini
    mohon maaf nih gan ane nanya lagi.
    kali ini ane punya masalah pas lagi compile, sebelumnya ini aplikasi bisa dirunning gan tapi gatau kenapa pas besokannya ane running malah gabisa gan.
    ane build sama deploy ga ada yang error gan, tapi pas lagi nginstal aplikasi di emulator malah muncul begini gan

    [attachment=2900]

    ada yang ngerti sama masalah ane gak gan? :woa:
     

    Attached Files:

  2. Chrisnado

    Chrisnado Administrator Staff Member

    Joined:
    May 7, 2013
    Messages:
    1,862
    bisa disertakan gak XML sama C#??
    ada error di line 46 potition 61 tuhh
     
  3. hendra07saputra

    hendra07saputra New Member

    Joined:
    Apr 4, 2014
    Messages:
    12
    ini xamlnya gan MainPage.xaml
    Code:
     <phone:PhoneApplicationPage
        x:Class="kuis1.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"
        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">
            <Rectangle 
            VerticalAlignment="Top" HorizontalAlignment="Stretch" 
            Height="200" Fill="#FF3182C1" />
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <!-- LOCALIZATION NOTE:
                To localize the displayed strings copy their values to appropriately named
                keys in the app's neutral language resource file (AppResources.resx) then
                replace the hard-coded text value between the attributes' quotation marks
                with the binding clause whose path points to that string name.
    
                For example:
    
                    Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
    
                This binding points to the template's string resource named "ApplicationTitle".
    
                Adding supported languages in the Project Properties tab will create a
                new resx file per language that can carry the translated values of your
                UI strings. The binding in these examples will cause the value of the
                attributes to be drawn from the .resx file that matches the
                CurrentUICulture of the app at run time.
             -->
    
            <!--TitlePanel contains the name of the application and page title-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                    <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
                    <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
                    <TextBlock Height="34" HorizontalAlignment="Left" Name="txtCorrectKuis" Text="Correct: " VerticalAlignment="Top" Width="200" TextAlignment="Center" FontSize="20" TextWrapping="Wrap" Foreground="White" />
                    <TextBlock Height="34" Name="txtTimerKuis" Text="Time Left:" Width="200" TextAlignment="Center" FontSize="20" TextWrapping="Wrap" Foreground="White" />            
            </StackPanel>
    
            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentPanelKuis" Margin="-17,180,-24,9" Grid.RowSpan="2" Background="White" Height="578" Width="497">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="212" />
                    <ColumnDefinition Width="270" />
                </Grid.ColumnDefinitions>
                <TextBlock Height="171" HorizontalAlignment="Left" Margin="27,18,0,0" Name="txtQuestionKuis" Text="Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing " VerticalAlignment="Top" Width="442" TextAlignment="Center" FontSize="20" TextWrapping="Wrap" Grid.ColumnSpan="2" Foreground="#FF6F6F6F" />
                <Button Content="A" HorizontalAlignment="Left" Margin="10,400,0,116" Name="btnAKuis" Width="468" Click="btnAImages_Click" Grid.ColumnSpan="2" Foreground="White" Background="#FF3182C1" BorderBrush="White" BorderThickness="0" Height="72" />
                <Button Content="B" Height="72" HorizontalAlignment="Left" Margin="10,454,0,0" Name="btnBKuis" VerticalAlignment="Top" Width="468" Click="btnBImages_Click" Grid.ColumnSpan="2" Foreground="White" Background="#FF3182C1" BorderThickness="0" />
                <Button Content="C" Height="72" HorizontalAlignment="Left" Margin="10,508,0,0" Name="btnCKuis" VerticalAlignment="Top" Width="468" Click="btnCImages_Click" Grid.ColumnSpan="2" Foreground="White" Background="#FF3182C1" BorderBrush="White" BorderThickness="0" />
             </Grid>
    
            <!--Uncomment to see an alignment grid to help ensure your controls are
                aligned on common boundaries.  The image has a top margin of -32px to
                account for the System Tray. Set this to 0 (or remove the margin altogether)
                if the System Tray is hidden.
    
                Before shipping remove this XAML and the image itself.-->
            <!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
        </Grid>
    
    </phone:PhoneApplicationPage> 
    ini C#-nya gan MainPage.xaml.cs
    Code:
     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.ComponentModel;
    using System.IO;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Media;
    using System.Windows.Resources;
    using Coding4Fun.Phone.Controls;
    using Microsoft.Phone.Tasks;
    using System.Windows.Navigation;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using kuis1.Resources;
    using Kuis1;
    
    
    namespace kuis1
    {
        public partial class MainPage : PhoneApplicationPage
        {
            private String resultToShare = "";
    
            private Boolean isKuisFinished = false;
    
            private Boolean hasStarted_Kuis = false;
    
            private int corrected_Kuis = 0;
    
            private int totalTimeElapsed_Kuis = 0;
    
            private int seconds_Kuis = 0;
    
            private int totalQuestions_Kuis = 0;
    
            private List<Question> questions_Kuis = new List<Question>();
            private Question currentQuestion_Kuis = new Question();
    
            private System.Windows.Threading.DispatcherTimer timer_Kuis;
    
            private SoundEffect correctSound, wrongSound;
    
            MessagePrompt gameFinished;
    
            // Constructor
            public MainPage()
            {
                InitializeComponent();
    
                FrameworkDispatcher.Update();
    
                this.LoadSound("correct.wav", out correctSound);
                this.LoadSound("wrong.wav", out wrongSound);
    
                this.initialize_Kuis();
                this.startKuis();
    
                // Sample code to localize the ApplicationBar
                //BuildLocalizedApplicationBar();
            }
    
            void messagePromptKuis_Completed(object sender, PopUpEventArgs<String, PopUpResult> e)
            {
                seconds_Kuis = 0;
                if (questions_Kuis.Count > 0)
                {
                    questions_Kuis.RemoveAt(0);
                    if (questions_Kuis.Count > 0)
                    {
                        this.nextQuestion_Kuis();
                        timer_Kuis.Start();
                    }
                    else
                    {
                        this.stopKuis();
                    }
                }
                else
                {
                    this.stopKuis();
                }
            }
    
            void showGameFinished_Completed(object sender, PopUpEventArgs<String, PopUpResult> e)
            {
                gameFinished.Hide();
                this.restart();
            }
    
            private void showGameFinished()
            {
                int totalScore = corrected_Kuis;
                int totalQuestions = totalQuestions_Kuis;
                int totalSecondsElapsed = totalTimeElapsed_Kuis;
                gameFinished = new MessagePrompt();
                gameFinished.Title = "Game Finished";
                gameFinished.Message = "Game Finished with a total score of: " + totalScore + "/" + totalQuestions + " and a total of " + totalSecondsElapsed + " seconds of elapsed time.\n\nClick Share Results if you want to share your results to your friends and click the Retry if you want to play again.";
                resultToShare = "I finished the playing BundledFun with a total score of: " + totalScore + "/" + totalQuestions + " and a total of " + totalSecondsElapsed + " seconds of elapsed time.";
                Button btnShare = new Button() { Content = "Share Results" };
                btnShare.Click += new RoutedEventHandler(btnShare_Click);
                Button btnRetry = new Button() { Content = "Retry" };
                btnRetry.Click += new RoutedEventHandler(btnRetry_Click);
                gameFinished.ActionPopUpButtons.Add(btnShare);
                gameFinished.ActionPopUpButtons.Add(btnRetry);
                gameFinished.Show();
            }
    
            private void btnShare_Click(object sender, RoutedEventArgs e)
            {
                ShareStatusTask shareStatusTask = new ShareStatusTask();
                shareStatusTask.Status = "Windows Phone Facebook Integration Development Test.";
                shareStatusTask.Show();
            }
    
            private void btnRetry_Click(object sender, RoutedEventArgs e)
            {
                gameFinished.Hide();
                this.restart();
            }
    
            private void restart()
            {
                isKuisFinished = false;
    
                hasStarted_Kuis = false;
    
                corrected_Kuis = 0;
    
                totalTimeElapsed_Kuis = 0;
    
                seconds_Kuis = 0;
    
                totalQuestions_Kuis = 0;
    
                txtCorrectKuis.Text = "";
                txtQuestionKuis.Text = "";
                txtTimerKuis.Text = "";
    
                btnAKuis.IsEnabled = true;
                btnBKuis.IsEnabled = true;
                btnCKuis.IsEnabled = true;
    
                timer_Kuis.Stop();
    
                questions_Kuis = new List<Question>();
                currentQuestion_Kuis = new Question();
    
                this.initialize_Kuis();
    
                MainPage.SelectedIndex = 0;
    
                this.startKuis();
            }
    
            private List<E> ShuffleList<E>(List<E> inputList)
            {
                List<E> randomList = new List<E>();
    
                Random r = new Random();
                int randomIndex = 0;
                while (inputList.Count > 0)
                {
                    randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list
                    randomList.Add(inputList[randomIndex]); //add it to the new, random list
                    inputList.RemoveAt(randomIndex); //remove to avoid duplicates
                }
    
                return randomList; //return the new random list
            }
    
            private void LoadSound(String SoundFilePath, out SoundEffect Sound)
            {
                Sound = null;
                try
                {
                    StreamResourceInfo SoundFileInfo = App.GetResourceStream(new Uri(SoundFilePath, UriKind.Relative));
                    Sound = SoundEffect.FromStream(SoundFileInfo.Stream);
                }
                catch (NullReferenceException)
                {
                    MessageBox.Show("Couldn't load sound " + SoundFilePath);
                }
            }
    
            private Boolean isEverythingFinished()
            {
                if (isKuisFinished)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            private void pauseKuis()
            {
                timer_Kuis.Stop();
            }
    
            private void resumeKuis()
            {
                timer_Kuis.Start();
            }
    
            private void btnAImages_Click(object sender, RoutedEventArgs e)
            {
                this.compareKuis(btnAKuis.Content.ToString());
            }
    
            private void btnBImages_Click(object sender, RoutedEventArgs e)
            {
                this.compareKuis(btnBKuis.Content.ToString());
            }
    
            private void btnCImages_Click(object sender, RoutedEventArgs e)
            {
                this.compareKuis(btnCKuis.Content.ToString());
            }
    
            private void nextQuestion_Kuis()
            {
                questions_Kuis = ShuffleList<Question>(questions_Kuis);
                currentQuestion_Kuis = questions_Kuis.ElementAt<Question>(0);
                txtQuestionKuis.Text = currentQuestion_Kuis.text;
                txtTimerKuis.Text = "Time Left: " + currentQuestion_Kuis.timer;
                btnAKuis.Content = currentQuestion_Kuis.a;
                btnBKuis.Content = currentQuestion_Kuis.b;
                btnCKuis.Content = currentQuestion_Kuis.c;
            }
    
            private void compareKuis(String answer)
            {
                timer_Kuis.Stop();
    
                if (answer.Equals(currentQuestion_Kuis.answer))
                {
                    this.correctSound.Play();
                    corrected_Kuis++;
                    totalTimeElapsed_Kuis += (30 - Convert.ToInt16(txtTimerKuis.Text.Substring(10)));
                    txtCorrectKuis.Text = "Correct: " + corrected_Kuis + "/" + totalQuestions_Kuis;
    
                    var messagePrompt = new MessagePrompt();
                    messagePrompt.Title = "Correct Answer";
                    messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
                    {
                        Result = messagePrompt.Value,
                        PopUpResult = PopUpResult.Ok
                    });
    
                    messagePrompt.Completed += messagePromptKuis_Completed;
                    messagePrompt.Show();
                }
                else
                {
                    this.wrongSound.Play();
                    var messagePrompt = new MessagePrompt();
                    messagePrompt.Title = "Wrong Answer";
                    messagePrompt.Message = "The correct answer is: " + currentQuestion_Kuis.answer;
                    messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>
                    {
                        Result = messagePrompt.Value,
                        PopUpResult = PopUpResult.Ok
                    });
    
                    messagePrompt.Completed += messagePromptKuis_Completed;
                    messagePrompt.Show();
                }
            }
    
            void timer_Tick_Kuis(object sender, EventArgs e)
            {
                seconds_Kuis++;
                int timeLeft = currentQuestion_Kuis.timer - seconds_Kuis;
                if (timeLeft > 0)
                {
                    txtTimerKuis.Text = "Time Left: " + timeLeft;
                }
                else
                {
                    seconds_Kuis = 0;
                    if (questions_Kuis.Count > 0)
                    {
                        questions_Kuis.RemoveAt(0);
                        if (questions_Kuis.Count > 0)
                        {
                            this.nextQuestion_Kuis();
                        }
                        else
                        {
                            this.stopKuis();
                        }
                    }
                    else
                    {
                        this.stopKuis();
                    }
                }
            }
    
            private void stopKuis()
            {
                seconds_Kuis = 0;
                timer_Kuis.Stop();
                isKuisFinished = true;
                btnAKuis.IsEnabled = false;
                btnBKuis.IsEnabled = false;
                btnCKuis.IsEnabled = false;
                MainPage.SelectedIndex = 1;
    
                if (this.isEverythingFinished())
                {
                    this.showGameFinished();
                }
            }
    
            private void startKuis()
            {
                txtTimerKuis.Text = "Time Left: " + currentQuestion_Kuis.timer;
                timer_Kuis.Start();
                this.nextQuestion_Kuis();
                hasStarted_Kuis = true;
            }
    
            private void initialize_Kuis()
            {
                Question question = null;
                question = null;
                question = new Question();
                question.text = "Is an American multinational computer software company founded in 1982 and headquartered in San Jose, California, United States.";
                question.a = "Gimp";
                question.b = "Adobe Systems";
                question.c = "Microsoft";
                question.answer = "Adobe Systems";
                question.timer = 30;
                questions_Kuis.Add(question);
    
                question = null;
                question = new Question();
                question.text = "Di Kota manakah presiden Soekarno Dilahirkan?";
                question.a = "Jakarta";
                question.b = "Semarang";
                question.c = "Blitar";
                question.answer = "Blitar";
                question.timer = 30;
                questions_Kuis.Add(question);
    
                totalQuestions_Kuis = questions_Kuis.Count;
                txtCorrectKuis.Text = "Correct: " + corrected_Kuis + "/" + totalQuestions_Kuis;
    
                timer_Kuis = new System.Windows.Threading.DispatcherTimer();
                timer_Kuis.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 500 Milliseconds
                timer_Kuis.Tick += new EventHandler(timer_Tick_Kuis);
            }
            // Sample code for building a localized ApplicationBar
            //private void BuildLocalizedApplicationBar()
            //{
            //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
            //    ApplicationBar = new ApplicationBar();
    
            //    // Create a new button and set the text value to the localized string from AppResources.
            //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
            //    appBarButton.Text = AppResources.AppBarButtonText;
            //    ApplicationBar.Buttons.Add(appBarButton);
    
            //    // Create a new menu item with the localized string from AppResources.
            //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
            //    ApplicationBar.MenuItems.Add(appBarMenuItem);
            //}
            private void btnRestart_Click(object sender, RoutedEventArgs e)
            {
                this.restart();
            }
    
            public static int SelectedIndex { get; set; }
    
            public object totalTimeElapsed_Songs { get; set; }
        }
    } 
     
  4. mabaega

    mabaega Well-Known Member

    Joined:
    Nov 9, 2013
    Messages:
    2,735
    sepertinya kesalahan di design code,
    coba buat form baru kemudian pas Control pada Form dan copas C# code dalam form nya ke form yang baru.
     

Share This Page