[英]How do I add a 'DropShadow' effect to a control (box/grid) in a Windows Store App using XAML/C#?
[英]How do I port a simple c# console app into a Windows Store app (XAML)?
我们制作了一个简单的控制台应用程序,可以接收句子和段落并将其转换为Pig Latin。 我知道,并不是所有有用的东西,但这只是为了练习。
现在,我想将其放入Windows Store应用程序中作为附加练习。 我用两个文本框和一个按钮在VS中模拟了设计,但是我不确定如何将其“装配”起来。
这是致辞:
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;
}
}
如果您使用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中获取示例可以帮助您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.