locked
Windows Destop App Conversion to Windows Store APP

    Question

  • I've made a windows Desktop App and now in the process of making a Windows 8/8.1/10 Store App version of the program. I know I have to use more MVVM coding in order to get this to work appropriately, in addition to more code behind. For those that would like to see the original desktop program, it is located at
    https://github.com/JescoInc/Japanese-and-English-Speech-Dictionary

    So, Here are the classes i've developed.

        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
                queryXML();
            }
    
            private void queryXML()
            {
                string xmlPath = "JapaneseEnglishData.xml";
                XDocument xDoc = XDocument.Load(xmlPath);
    
                var lstWord = xDoc.Root.Elements("Word").Select(x => new
                {
                    English = x.Element("English").Value
                }).ToList();
    
                this.listBx.ItemsSource = lstWord;
                }
            }
        }

    XAML code:

    <Page
        x:Class="WindowsEJDictionary.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:WindowsEJDictionary"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto">
                </RowDefinition>
            </Grid.RowDefinitions>
    
            <Button Content="Button" HorizontalAlignment="Left" Margin="718,625,0,0" VerticalAlignment="Top" Width="144"/>
            <ListBox Name="listBx" HorizontalAlignment="Left" Height="398" Margin="109,255,0,0" VerticalAlignment="Top" Width="494"/>
    
        </Grid>
    </Page>
    



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace WindowsEJDictionary
    {
        public class xmlData
        {
            private string english;
            private string romaji;
            private string kanji;
    
            public string English
            {
    
                get { return english; }
    
                set { english = value; }
    
            }
    
            public string Romaji
            {
                get { return romaji; }
    
                set { romaji = value; }
            }
    
            public string Kanji
            {
                get { return kanji; }
    
                set { kanji = value; }
            }
        }
    }

    The issue is, how it currently stands is I have a string show up that is completely unintended.
    Shown in the image below:

    MMy question is how do I remove the unwanted text and keep the list? (Note: I haven't used LINQ much and i'm terrible at it)

    Monday, April 13, 2015 1:54 AM

Answers

  • So, the answer to my question is as followed. rather than using LINQ and Lambda expressions, I should only need to use LINQ by itself. So, lets break this down.

    var listOEnglish = from wordList in XDoc.Root.Elements("Word")

    // This line is declaring the Root Element that we want to iterate through.

    select wordList.Element("English").Value;

    // this line is setting the child element we want to iterate through with the words within the tag of English.

    listBx.ItemsSource = listOEnglish.ToList();

    // this line sets the itemsource or the databinding for the list box to be from the listOEnglish as a list.

    Many Thanks to Jesse from the FlatRedBall (FRB) community for showing me how to just work with LINQ and help me come up with the solution.

    private void queryXML2()
    {
        string xmlPath = "JapaneseEnglishData.xml";
        XDocument XDoc = XDocument.Load(xmlPath);
    
        var listOEnglish = from wordList in XDoc.Root.Elements("Word")
                           select wordList.Element("English").Value;
        listBx.ItemsSource = listOEnglish.ToList();
    }
    • Marked as answer by Jesse Glover Tuesday, April 14, 2015 12:35 AM
    Tuesday, April 14, 2015 12:34 AM

All replies

  • I think your Linq is messed up. You'll need to post the contents of the XML so we can see what it's putting out.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, April 13, 2015 2:26 PM
    Moderator
  • Here's the XML File i'm currently using.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <!--This is a generated XML File-->
    <WordList>
      <Word>
        <English>Me(Male)</English>
        <Romaji>boku</Romaji>
        <Kanji>ぼく</Kanji>
      </Word>
      <Word>
        <English>I(Male)</English>
        <Romaji>boku</Romaji>
        <Kanji>ぼく</Kanji>
      </Word>
      <Word>
        <English>Me(Female)</English>
        <Romaji>watashi</Romaji>
        <Kanji>わたし</Kanji>
      </Word>
      <Word>
        <English>I(Female)</English>
        <Romaji>watashi</Romaji>
        <Kanji>わたし</Kanji>
      </Word>
      <Word>
        <English>I(Tough Male)</English>
        <Romaji>ore</Romaji>
        <Kanji>俺</Kanji>
      </Word>
      <Word>
        <English>Me(Tough Male)</English>
        <Romaji>ore</Romaji>
        <Kanji>俺</Kanji>
      </Word>
      <Word>
        <English>Yes</English>
        <Romaji>hai</Romaji>
        <Kanji>はい</Kanji>
      </Word>
      <Word>
        <English>No</English>
        <Romaji>iie</Romaji>
        <Kanji>いいえ</Kanji>
      </Word>
      <Word>
        <English>What</English>
        <Romaji>nani</Romaji>
        <Kanji>なに</Kanji>
      </Word>
      <Word>
        <English>Name</English>
        <Romaji>namae</Romaji>
        <Kanji>なまえ</Kanji>
      </Word>
      <Word>
        <English>Nice to meet you</English>
        <Romaji>Hajimemashite</Romaji>
        <Kanji>はじめまして</Kanji>
      </Word>
      <Word>
        <English>want to go to</English>
        <Romaji>ni ikitai</Romaji>
        <Kanji>にいきたい </Kanji>
      </Word>
      <Word>
        <English>want to eat</English>
        <Romaji>wo tabetai</Romaji>
        <Kanji>をたべたい</Kanji>
      </Word>
      <Word>
        <English>want to drink</English>
        <Romaji>wo nomitai</Romaji>
        <Kanji>をのみたい</Kanji>
      </Word>
      <Word>
        <English>water</English>
        <Romaji>omizu</Romaji>
        <Kanji>おみず</Kanji>
      </Word>
      <Word>
        <English>can't eat</English>
        <Romaji>wo taberarenai</Romaji>
        <Kanji>をたべられない</Kanji>
      </Word>
      <Word>
        <English>excuse me</English>
        <Romaji>sumimasen</Romaji>
        <Kanji>すみません</Kanji>
      </Word>
      <Word>
        <English>sorry</English>
        <Romaji>sumimasen</Romaji>
        <Kanji>すみません</Kanji>
      </Word>
      <Word>
        <English>sorry</English>
        <Romaji>gomen nasai</Romaji>
        <Kanji>ごめんなさい</Kanji>
      </Word>
      <Word>
        <English>thank you</English>
        <Romaji>arigatou gozaimasu</Romaji>
        <Kanji>ありがとうございます</Kanji>
      </Word>
      <Word>
        <English>want to buy</English>
        <Romaji>wo kaitai</Romaji>
        <Kanji>を かいたい</Kanji>
      </Word>
      <Word>
        <English>want to see</English>
        <Romaji>wo mitai</Romaji>
        <Kanji>を みたい</Kanji>
      </Word>
      <Word>
        <English>good morning</English>
        <Romaji>ohayou gozaimasu</Romaji>
        <Kanji>おはようございます</Kanji>
      </Word>
      <Word>
        <English>good afternoon</English>
        <Romaji>konnichi wa</Romaji>
        <Kanji>こんにちは</Kanji>
      </Word>
      <Word>
        <English>good evening</English>
        <Romaji>konnban wa</Romaji>
        <Kanji>こんばんは</Kanji>
      </Word>
      <Word>
        <English>How are you</English>
        <Romaji>ogenki desu ka</Romaji>
        <Kanji>おげんきですか</Kanji>
      </Word>
      <Word>
        <English>i'm fine</English>
        <Romaji>genki desu</Romaji>
        <Kanji>げんきです</Kanji>
      </Word>
      <Word>
        <English>hotel</English>
        <Romaji>hoteru</Romaji>
        <Kanji>ホテル</Kanji>
      </Word>
      <Word>
        <English>train</English>
        <Romaji>densha</Romaji>
        <Kanji>でんしゃ</Kanji>
      </Word>
      <Word>
        <English>station</English>
        <Romaji>eki</Romaji>
        <Kanji>えき</Kanji>
      </Word>
      <Word>
        <English>Hospital</English>
        <Romaji>byouin</Romaji>
        <Kanji>びょういん</Kanji>
      </Word>
      <Word>
        <English>where is</English>
        <Romaji>wa doko</Romaji>
        <Kanji>はどこ</Kanji>
      </Word>
      <Word>
        <English>bathroom</English>
        <Romaji>otearai</Romaji>
        <Kanji>おてあらい</Kanji>
      </Word>
      <Word>
        <English>ticket</English>
        <Romaji>kippu</Romaji>
        <Kanji>きっぷ</Kanji>
      </Word>
      <Word>
        <English>money</English>
        <Romaji>okane</Romaji>
        <Kanji>おかね</Kanji>
      </Word>
      <Word>
        <English>bank</English>
        <Romaji>ginkou</Romaji>
        <Kanji>ぎんこう</Kanji>
      </Word>
      <Word>
        <English>police</English>
        <Romaji>keisatsu</Romaji>
        <Kanji>けいさつ</Kanji>
      </Word>
      <Word>
        <English>How much</English>
        <Romaji>ikura</Romaji>
        <Kanji>いくら</Kanji>
      </Word>
      <Word>
        <English>plane</English>
        <Romaji>hikouki</Romaji>
        <Kanji>ひこうき</Kanji>
      </Word>
      <Word>
        <English>foreigner</English>
        <Romaji>gaijin</Romaji>
        <Kanji>がいじん</Kanji>
      </Word>
      <Word>
        <English>Japan</English>
        <Romaji>nihon</Romaji>
        <Kanji>にほん</Kanji>
      </Word>
      <Word>
        <English>Japanese</English>
        <Romaji>nihonjin</Romaji>
        <Kanji>にほんじん</Kanji>
      </Word>
      <Word>
        <English>person</English>
        <Romaji>hito</Romaji>
        <Kanji>ひと</Kanji>
      </Word>
      <Word>
        <English>ouch</English>
        <Romaji>itai</Romaji>
        <Kanji>いたい</Kanji>
      </Word>
      <Word>
        <English>hurt</English>
        <Romaji>itai</Romaji>
        <Kanji>いたい</Kanji>
      </Word>
      <Word>
        <English>noon</English>
        <Romaji>ohiru</Romaji>
        <Kanji>おひる</Kanji>
      </Word>
      <Word>
        <English>morning</English>
        <Romaji>asa</Romaji>
        <Kanji>あさ</Kanji>
      </Word>
      <Word>
        <English>evening</English>
        <Romaji>yoru</Romaji>
        <Kanji>よる</Kanji>
      </Word>
      <Word>
        <English>meal</English>
        <Romaji>gohan</Romaji>
        <Kanji>ごはん</Kanji>
      </Word>
      <Word>
        <English>play</English>
        <Romaji>asobu</Romaji>
        <Kanji>あそぶ</Kanji>
      </Word>
      <Word>
        <English>listen</English>
        <Romaji>kiku</Romaji>
        <Kanji>きく</Kanji>
      </Word>
      <Word>
        <English>expensive</English>
        <Romaji>takai</Romaji>
        <Kanji>たかい</Kanji>
      </Word>
      <Word>
        <English>half</English>
        <Romaji>hanbun</Romaji>
        <Kanji>はんぶん</Kanji>
      </Word>
      <Word>
        <English>cheap</English>
        <Romaji>yasui</Romaji>
        <Kanji>やすい</Kanji>
      </Word>
      <Word>
        <English>room</English>
        <Romaji>heya</Romaji>
        <Kanji>へや</Kanji>
      </Word>
      <Word>
        <English>art museum</English>
        <Romaji>bijutsukan</Romaji>
        <Kanji>びじゅつかん</Kanji>
      </Word>
      <Word>
        <English>park</English>
        <Romaji>koen</Romaji>
        <Kanji>こうえん</Kanji>
      </Word>
      <Word>
        <English>zoo</English>
        <Romaji>doubutsuen</Romaji>
        <Kanji>どうぶつえん</Kanji>
      </Word>
      <Word>
        <English>express train</English>
        <Romaji>kaisoku</Romaji>
        <Kanji>かいそく</Kanji>
      </Word>
      <Word>
        <English>subway</English>
        <Romaji>chikatetsu</Romaji>
        <Kanji>ちかてつ</Kanji>
      </Word>
      <Word>
        <English>car</English>
        <Romaji>kuruma</Romaji>
        <Kanji>くるま</Kanji>
      </Word>
      <Word>
        <English>close</English>
        <Romaji>chikai</Romaji>
        <Kanji>ちかい</Kanji>
      </Word>
      <Word>
        <English>far</English>
        <Romaji>toi</Romaji>
        <Kanji>とおい</Kanji>
      </Word>
      <Word>
        <English>yummy</English>
        <Romaji>oishii</Romaji>
        <Kanji>おいしい</Kanji>
      </Word>
      <Word>
        <English>good</English>
        <Romaji>oishii</Romaji>
        <Kanji>おいしい</Kanji>
      </Word>
      <Word>
        <English>tasty</English>
        <Romaji>oishii</Romaji>
        <Kanji>おいしい</Kanji>
      </Word>
      <Word>
        <English>spacious</English>
        <Romaji>hiroi</Romaji>
        <Kanji>ひろい</Kanji>
      </Word>
      <Word>
        <English>narrow</English>
        <Romaji>semai</Romaji>
        <Kanji>せまい</Kanji>
      </Word>
      <Word>
        <English>warm</English>
        <Romaji>atatakai</Romaji>
        <Kanji>あたたかい</Kanji>
      </Word>
      <Word>
        <English>cold</English>
        <Romaji>samui</Romaji>
        <Kanji>さむい</Kanji>
      </Word>
      <Word>
        <English>bright</English>
        <Romaji>akarui</Romaji>
        <Kanji>あかるい</Kanji>
      </Word>
      <Word>
        <English>dark</English>
        <Romaji>kurai</Romaji>
        <Kanji>くらい</Kanji>
      </Word>
      <Word>
        <English>one</English>
        <Romaji>ichi</Romaji>
        <Kanji>いち</Kanji>
      </Word>
      <Word>
        <English>two</English>
        <Romaji>ni</Romaji>
        <Kanji>に</Kanji>
      </Word>
      <Word>
        <English>three</English>
        <Romaji>san</Romaji>
        <Kanji>さん</Kanji>
      </Word>
      <Word>
        <English>four</English>
        <Romaji>shi</Romaji>
        <Kanji>し</Kanji>
      </Word>
      <Word>
        <English>five</English>
        <Romaji>go</Romaji>
        <Kanji>ご</Kanji>
      </Word>
      <Word>
        <English>six</English>
        <Romaji>roku</Romaji>
        <Kanji>ろく</Kanji>
      </Word>
      <Word>
        <English>seven</English>
        <Romaji>shichi</Romaji>
        <Kanji>しち</Kanji>
      </Word>
      <Word>
        <English>eight</English>
        <Romaji>hachi</Romaji>
        <Kanji>はち</Kanji>
      </Word>
      <Word>
        <English>nine</English>
        <Romaji>ku</Romaji>
        <Kanji>く</Kanji>
      </Word>
      <Word>
        <English>ten</English>
        <Romaji>juu</Romaji>
        <Kanji>じゅう</Kanji>
      </Word>
      <Word>
        <English>one hundred</English>
        <Romaji>hyaku</Romaji>
        <Kanji>百</Kanji>
      </Word>
      <Word>
        <English>one thousand</English>
        <Romaji>sen</Romaji>
        <Kanji>せん</Kanji>
      </Word>
      <Word>
        <English>ten thousand</English>
        <Romaji>man</Romaji>
        <Kanji>まん</Kanji>
      </Word>
      <Word>
        <English>time</English>
        <Romaji>jikan</Romaji>
        <Kanji>じかん</Kanji>
      </Word>
      <Word>
        <English>O'clock</English>
        <Romaji>ji</Romaji>
        <Kanji>じ</Kanji>
      </Word>
      <Word>
        <English>fall</English>
        <Romaji>aki</Romaji>
        <Kanji>あき</Kanji>
      </Word>
      <Word>
        <English>winter</English>
        <Romaji>fuyu</Romaji>
        <Kanji>ふゆ</Kanji>
      </Word>
      <Word>
        <English>spring</English>
        <Romaji>haru</Romaji>
        <Kanji>はる</Kanji>
      </Word>
      <Word>
        <English>summer</English>
        <Romaji>natsu</Romaji>
        <Kanji>なつ</Kanji>
      </Word>
      <Word>
        <English>Monday</English>
        <Romaji>getsuyoubi</Romaji>
        <Kanji>げつようび</Kanji>
      </Word>
      <Word>
        <English>Tuesday</English>
        <Romaji>kayoubi</Romaji>
        <Kanji>かようび</Kanji>
      </Word>
      <Word>
        <English>Wednesday</English>
        <Romaji>suiyoubi</Romaji>
        <Kanji>すいようび</Kanji>
      </Word>
      <Word>
        <English>Thursday</English>
        <Romaji>mokuyoubi</Romaji>
        <Kanji>もくようび</Kanji>
      </Word>
      <Word>
        <English>Friday</English>
        <Romaji>kinyoubi</Romaji>
        <Kanji>きんようび</Kanji>
      </Word>
      <Word>
        <English>Saturday</English>
        <Romaji>doyoubi</Romaji>
        <Kanji>どようび</Kanji>
      </Word>
      <Word>
        <English>Sunday</English>
        <Romaji>nichiyoubi</Romaji>
        <Kanji>にちようび</Kanji>
      </Word>
      <Word>
        <English>Weekend</English>
        <Romaji>shuumatsu</Romaji>
        <Kanji>しゅうまつ</Kanji>
      </Word>
      <Word>
        <English>vacation</English>
        <Romaji>yasumi</Romaji>
        <Kanji>やすみ</Kanji>
      </Word>
      <Word>
        <English>rest</English>
        <Romaji>yasumi</Romaji>
        <Kanji>やすみ</Kanji>
      </Word>
      <Word>
        <English>Goodnight</English>
        <Romaji>oyasumi nasai</Romaji>
        <Kanji>おやすみなさい</Kanji>
      </Word>
    </WordList>

    Monday, April 13, 2015 10:20 PM
  • Update, i've also tried a different variation of LINQ to XML and produced more unwanted results as followed.

            private void queryXML()
            {
                string xmlPath = "JapaneseEnglishData.xml";
                XDocument xDoc = XDocument.Load(xmlPath);
    
                //var lstWord = xDoc.Root.Elements("Word").Select(x => new
                //{
                //    English = x.Element("English").Value
                //}).ToList();
                var lstWord = from item in xDoc.Descendants("Word")
                              select new
                              {
                                  English = item.Element("English").Value,
                                  //Romaji = item.Element("Romaji").Value,
                                  //Kanji = item.Element("Kanji").Value
                              };
                foreach (var i in lstWord)
                {
                    listBx.ItemsSource = i.English.ToList();
                }
                
                }

    And here is the image for the result.

    Monday, April 13, 2015 11:43 PM
  • So, the answer to my question is as followed. rather than using LINQ and Lambda expressions, I should only need to use LINQ by itself. So, lets break this down.

    var listOEnglish = from wordList in XDoc.Root.Elements("Word")

    // This line is declaring the Root Element that we want to iterate through.

    select wordList.Element("English").Value;

    // this line is setting the child element we want to iterate through with the words within the tag of English.

    listBx.ItemsSource = listOEnglish.ToList();

    // this line sets the itemsource or the databinding for the list box to be from the listOEnglish as a list.

    Many Thanks to Jesse from the FlatRedBall (FRB) community for showing me how to just work with LINQ and help me come up with the solution.

    private void queryXML2()
    {
        string xmlPath = "JapaneseEnglishData.xml";
        XDocument XDoc = XDocument.Load(xmlPath);
    
        var listOEnglish = from wordList in XDoc.Root.Elements("Word")
                           select wordList.Element("English").Value;
        listBx.ItemsSource = listOEnglish.ToList();
    }
    • Marked as answer by Jesse Glover Tuesday, April 14, 2015 12:35 AM
    Tuesday, April 14, 2015 12:34 AM