2013-10-25 101 views
0

我們製作了一個簡單的控制檯應用程序,它將句子和段落轉換成Pig Latin。我知道,並非所有有用的,但它是爲了實踐。如何將簡單的c#控制檯應用程序移植到Windows應用商店應用程序(XAML)中?

現在我想將它放入Windows應用商店應用作爲附加練習。我用VS和兩個文本框和一個按鈕嘲笑了這個設計,但是我不知道如何「完成」它。

這裏的odecay:

public static class Program 
{ 
    public static void Main(string[] args) 
    { 
     Console.Write("Enter your text: "); 

     var text = ""; 
     text = Console.ReadLine(); 
     piglatinize(text); 

    } 

    public static string piglatinize(string text) 
    { 

     string[] words = text.Split(' '); 
     string result = string.Empty; 

     foreach (string word in words) 
     { 
      char first = word[0]; 
      string rest = word.Length > 1 ? word.Substring(1) : string.Empty; 

      switch (word[word.Length - 1]) 
      { 
       case '?': 
       case '!': 
       case '.': 
       case ',': 
       case '\'': 
       case ':': 
       case ';': 

        result += rest.Substring(0, (rest.Length - 1)) + first + "ay" + word[word.Length - 1] + " "; 
        break; 
       default: 
        result += rest + first + "ay "; 
        break; 
      } 
     } 

     Console.WriteLine("Here is your Pig Latin:"); 
     Console.WriteLine(result); 

     return result; 

    } 
} 
+0

這是一個廣泛的問題。你面臨什麼問題? – kiewic

回答

0

如果您正在使用的這一切Visual Studio中的最簡單的事情是搶的模板的例子之一,並從那裏開始。

你將需要一個類實現iNotifyPropertyChanged

你的類可能看起來如此簡單:

public class PigLatinConverter : INotifyPropertyChanged 
{ 
    private string _originalText; 

    public string OriginalText 
    { 
     get { return _originalText; } 
     set 
     { 
      _originalText = value; 
      OnPropertyChanged("OriginalText"); 
     } 
    } 

    private string _piglatinizedText; 

    public string PiglatinizedText 
    { 
     get { return _piglatinizedText; } 
     set 
     { 
      _piglatinizedText = value; 
      OnPropertyChanged("PiglatinizedText"); 
     } 
    } 

    public void ConvertOriginalText() //your button calls this 
    { 
     //your pig latin logic here 

     // set _piglatinizedText to your output 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 
    protected void OnPropertyChanged(string name) 
    { 
     PropertyChangedEventHandler handler = PropertyChanged; 
     if (handler != null) 
     { 
      handler(this, new PropertyChangedEventArgs(name)); 
     } 
    } 
} 

對於XAML使用文本框和文本屬性綁定您新的屬性。從Visual Studio抓取示例應該可以幫助你。

+0

謝謝Jastill,我會試試看。 – grayspace

+0

如果這適用於您,請將其標記爲已回答。 – Jastill

相關問題