开发者

Converting Silverlight browser app to windows phone app

I am using the code http://www.c-sharpcorner.com/UploadFile/prvn_131971/3285/

i want to convert it to windows phone app. The only problem i am facing is that the alphabets and words to be guessed are not coming to right places... I have tried alot... but I just cant move the positions of the grid and the stackpanel from the top of the app... Please help!

here is the code.

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.V开发者_如何学Pythonisibility = 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());
    }    
}
}

this is the link of originial app that i want to change

the problem is at the dashes and the letters

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

I cant post images otherwise i would have uploaded the screenshot of my app :-(


You can't just convert a Silverlight 4 application into a Windows Phone 7 application.

They both use different version of Silverlight and are on completely different platforms using different set of controls.

Try building it step by step and reuse any code that you can out of existing application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜