将Silverlight浏览器应用程序转换为Windows Phone应用程序

时间:2011-02-16 10:47:27

标签: c# silverlight-4.0 windows-phone-7

我正在使用代码http://www.c-sharpcorner.com/UploadFile/prvn_131971/3285/

我想将其转换为Windows手机应用程序。我面临的唯一问题是,猜测的字母和单词并没有到达正确的位置......我已经尝试了很多......但我不能从应用程序的顶部移动网格和堆栈面板的位置......请帮忙!

这是代码。

namespace Canhangman
{
public partial class MainPage : PhoneApplicationPage
{
    public int x = 0;
    StackPanel sp = new StackPanel();
    StackPanel sp_special = new StackPanel();
    List<TextBox> text = new List<TextBox>(); // keeping all textboxes
    StackPanel sp1;
    Grid g, g1;
    Rectangle r1;
    int nooftxtbox = -1;
    string[] words = new string[100] {"KARAKARTAL","BİLGİSAYAR","KİTAPLIK","FAALİYET","PANTOLON",
                                     "KİLİSE","TELEFON","CEYLAN","KANGURU","JANDARMA","PİYADE","MAKARNA",
                                     "KEVGİR","MALUMAT","GALERİ","ARABA","DİKELMEK","KALKMAK","OTURMAK",
                                     "GÖZLÜKÇÜ","DOĞUŞTAN","YAZICI","TARAYICI","ŞİFONYER","FASULYE","PAZARLIK",
                                     "KALDIRIM","İNDİRİM","SAĞANAK","ABAJUR","KARNIBAHAR","ÜNİFORMA","ÜNİVERSİTE",
                                     "AYAKLANMA","TEBESSÜM","MÜTEAHHİT","MÜBAŞİR","MÜSTEŞAR","MÜFETTİŞ","BAKANLIK",
                                     "CUMHURİYET","OSMANLI","PAŞAZADE","KUMBURGAZ","PANSİYON","TANSİYON","İLKOKUL",
                                     "KONSERVATUAR","KONGRE","KUMANDA","KEMER","ÇAKMAK","ÇAYDANLIK","CETVEL","BİSTÜYER",
                                     "KELEBEK","KAPLUMBAĞA","KORTEJ","TUHAF","BORNOZ","KAPŞON","OROTORYO","ORDİNARYÜS",
                                     "KERPİÇ","KALPAZAN","TASARRUF","MÜNECCİM","İLMİHAL","MUHBİR","LİZOZOM","RİBOZOM",
                                     "KLASÖR","KILAVUZ","MODÜLER","TEHLİKE","STATİK","MEKANİK","POTANSİYEL","KULAKLIK",
                                     "ARDIŞIK","ÇERÇEVE","MONİTÖR","SANDALYE","MERDİVEN","OTOBÜS","MİNİBÜS","KAREOKE",
                                     "KARTONPİYER","ÇEKMECE","ALIŞVERİŞ","KALDIRAÇ","KARINCA","KARBONAT","GERGEDAN",
                                     "İSTİRİDYE","TENEFFÜS","ORİGAMİ","BEZİK","EKONOMİ","GRAFİK"};
    public string s;

    public MainPage()
    {
        string[] alph = new string[29] {"A","B","C","Ç","D","E","F","G","Ğ","H","I","İ","J","K","L",
                                        "M","N","O","Ö","P","R","S","Ş","T","U","Ü","V","Y","Z"};

        // Required to initialize variables
        InitializeComponent();

        SolidColorBrush sb = new SolidColorBrush();
        sb.Color = Colors.Blue;

        sp.Height = 100;
        sp_special.Height = 100;

        sp.Background = sb;
        sp_special.Background = sb;
        sp.Orientation = System.Windows.Controls.Orientation.Horizontal;
        sp_special.Orientation = System.Windows.Controls.Orientation.Horizontal;
        Canvas.SetLeft(sp, 0);
        Canvas.SetLeft(sp_special,0);
        Canvas.SetTop(sp,0);
        Canvas.SetTop(sp_special,200);
        sp1 = new StackPanel();
        sp1.Background = sb;
        sp1.Orientation = System.Windows.Controls.Orientation.Horizontal;
        Canvas.SetLeft(sp1, 20);
        Canvas.SetTop(sp1, 100);
        g = new Grid();
        Canvas.SetLeft(g, 200);
        Canvas.SetTop(g, 320);
        g1 = new Grid();
        g.Height = 20;
        g1.Height= 20;          
        g.Width = 300;
        g1.Width =300;

        Canvas.SetLeft(g1, 200);
        Canvas.SetTop(g1, 300);
        ContentPanel.Children.Add(sp);
        ContentPanel.Children.Add(sp_special);
        ContentPanel.Children.Add(g);

        ContentPanel.Children.Add(g1);

        for (int i = 0; i < 29; i++)
        {
            Button b = new Button();
            b.Name = "b" + i;
            b.Content = alph[i];
            b.Width = 25;
            b.Height = 5;
            b.FontWeight = FontWeights.Bold;
            if(i<20)
            {
                sp.Children.Add(b);
                b.Click += new System.Windows.RoutedEventHandler(b_Click);
            }
            else
            {
                sp_special.Children.Add(b);
                b.Click += new System.Windows.RoutedEventHandler(b_Click);
            }
        }

        Random r = new Random();
        s = words[r.Next(0, words.Length)];
        for (int j = 0; j < s.Length; j++)
        {
            r1 = new Rectangle();
            r1.Width = 15;
            r1.Height = 5;
            SolidColorBrush sb1 = new SolidColorBrush();
            sb1.Color = Colors.Black;
            r1.Fill = sb1;
            TextBox t = new TextBox();
            t.Name = "t" + j;
            t.Text = s[j].ToString().ToUpper();
            t.Visibility = Visibility.Collapsed;
            t.Width = 25;
            t.Height = 5;
            t.IsEnabled = false;
            text.Add(t); // adding textBox to list
            g.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength((double)30) });
            g1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength((double)30) });
            g1.ShowGridLines = true;
            Grid.SetColumn(t, j);
            Grid.SetColumn(r1, j);
            if (t.Text != " ")
            {
                g.Children.Add(r1);
                g1.Children.Add(t);
            }
            nooftxtbox++;               
        }
    }

    private void b_Click(object sender, System.Windows.RoutedEventArgs e)
    {           
        bool iscomplete = true;
        bool flag = false;
        string bstr;
        TextBox txtName;
        bstr = ((Button)sender).Content.ToString();

        if (x != 6)
        {
            for (int j = 0; j <= nooftxtbox; j++)
            {
                txtName = g1.Children[j] as TextBox;
                if (txtName.Text == bstr)
                {
                    txtName.SetValue(Grid.ColumnProperty, j);
                    txtName.Visibility = Visibility.Visible;
                    txtName.IsEnabled = false;
                    ((Button)sender).Visibility = Visibility.Collapsed;
                    flag = true;
                }
                else
                {
                    ((Button)sender).Visibility = Visibility.Collapsed;
                }
            }
            if (!flag)
            {
                x = x + 1;
            }
            if (x == 1)
            {
                loop1.Visibility = Visibility.Collapsed;
                head.Visibility = Visibility.Visible;
            }
            if (x == 2)
            {
                loop1.Visibility = Visibility.Collapsed;
                head.Visibility = Visibility.Visible;
                body1.Visibility = Visibility.Visible;
            }
            if (x == 3)
            {
                loop1.Visibility = Visibility.Collapsed;
                head.Visibility = Visibility.Visible;
                body1.Visibility = Visibility.Visible;
                lefthand.Visibility = Visibility.Visible;
            }
            if (x == 4)
            {
                loop1.Visibility = Visibility.Collapsed;
                head.Visibility = Visibility.Visible;
                body1.Visibility = Visibility.Visible;
                lefthand.Visibility = Visibility.Visible;
                righthand.Visibility = Visibility.Visible;
            }
            if (x == 5)
            {
                loop1.Visibility = Visibility.Collapsed;
                head.Visibility = Visibility.Visible;
                body1.Visibility = Visibility.Visible;
                lefthand.Visibility = Visibility.Visible;
                righthand.Visibility = Visibility.Visible;
                leftleg.Visibility = Visibility.Visible;
            }
            if (x == 6)
            {
                loop1.Visibility = Visibility.Collapsed;
                head.Visibility = Visibility.Visible;
                body1.Visibility = Visibility.Visible;
                lefthand.Visibility = Visibility.Visible;
                righthand.Visibility = Visibility.Visible;
                leftleg.Visibility = Visibility.Visible;
                rightleg.Visibility = Visibility.Visible;
                deadtxt.Visibility = Visibility.Visible;
                trybutton.Visibility = Visibility.Visible;

                for (int i = 0; i < text.Count; i++)// checking whether user has completed the guess or not
                {
                    text[i].Visibility = Visibility.Visible;
                }
                iscomplete = false;
                sp.Visibility = Visibility.Collapsed;
                sp_special.Visibility = Visibility.Collapsed;
            }

            if(iscomplete)
            {
                bool complete = true;
                for (int i = 0; i < text.Count; i++)// checking whether user has completed the guess or not
                {
                    if (text[i].Visibility == Visibility.Collapsed)
                    {
                        complete = false;
                    }
                }

                if (complete)
                {
                    // safetxt and hiding the letter boxes
                    safetxt.Visibility = Visibility.Visible;
                    trybutton.Visibility = Visibility.Visible;
                    sp.Visibility = Visibility.Collapsed;
                    sp_special.Visibility = Visibility.Collapsed;

                    loop1.Visibility = Visibility.Visible;

                    //hiding the hanged man
                    head.Visibility = Visibility.Collapsed;
                    body1.Visibility = Visibility.Collapsed;
                    leftleg.Visibility = Visibility.Collapsed;
                    rightleg.Visibility = Visibility.Collapsed;
                    lefthand.Visibility = Visibility.Collapsed;
                    righthand.Visibility = Visibility.Collapsed;

                    //showing man walking away
                    head_Copy.Visibility = Visibility.Visible;
                    body1_Copy.Visibility = Visibility.Visible;
                    leftleg_Copy.Visibility = Visibility.Visible;
                    rightleg_Copy.Visibility = Visibility.Visible;
                    lefthand_Copy.Visibility = Visibility.Visible;
                    righthand_Copy.Visibility = Visibility.Visible;
                }
            }
        }
        else
        {
            deadtxt.Visibility = Visibility.Visible;
            loop1.Visibility = Visibility.Visible;
            head.Visibility = Visibility.Visible;
            body1.Visibility = Visibility.Visible;
            leftleg.Visibility = Visibility.Visible;
            rightleg.Visibility = Visibility.Visible;
            lefthand.Visibility = Visibility.Visible;
            righthand.Visibility = Visibility.Visible;
            trybutton.Visibility = Visibility.Visible;
        }
    }
    private void trybutton_Click(object sender, RoutedEventArgs e)
    {
        this.ContentPanel.Children.Add(new MainPage());
    }    
}
}

这是我想要更改的原始应用的链接

问题在于破折号和字母

http://www.sarayyayin.com/silverlighthangman/TestPage.html

我无法发布图片,否则我会上传我的应用程序的屏幕截图: - (

1 个答案:

答案 0 :(得分:0)

您不能只将Silverlight 4应用程序转换为Windows Phone 7应用程序。

他们都使用不同版本的Silverlight,并使用不同的控件集在完全不同的平台上。

尝试逐步构建它,并重用现有应用程序中的任何代码。