我想添加是否被单选按钮选中或不添加到C#和XAML [英] I want add is cheked radiobutton or not to the c# and xaml

查看:102
本文介绍了我想添加是否被单选按钮选中或不添加到C#和XAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   phone:phoneapplicationpage   xmlns:phone    #unknown" <!-   LayoutRoot是放置所有页面内容的根网格 ->  
    <  网格    ="   LayoutRoot" 已删除  透明"  xmlns:x   #unknown" <   grid.rowdefinitions  > 
            <  行定义    ="  自动" / <  行定义    ="   *" / <  /grid.rowdefinitions  > 

        <!-   TitlePanel包含应用程序的名称和页面标题 ->  
        <  堆栈面板    ="   TitlePanel"  grid.row    0" 保证金   12,17,0,28" <  文本块    ="   ApplicationTitle" 文本   MY APPLICATION" 样式   {StaticResource PhoneTextNormalStyle}" / > 
            <  文本块    ="   qu" 文本  页面名称"    边距  ="  9,-7,0,0" 样式  ="    / > 
        <  /stackpanel  > 

        <!-   ContentPanel-在此处放置其他内容 ->  
        <  网格    ="   grd"  grid.row    1" 保证金   12,0,12,0" <  列表框    ="   listBox" <   listbox.itemtemplate  > 
                    <  数据模板 > 
                        <  堆栈面板    ="   10" <  文本块    ="   {Binding Txt}" / <  单选按钮    ="   a1" 组名   q"   内容  ="  {Binding Answer1}" / > 
                            <  单选按钮    ="   a2" 组名  > q"    内容  ="  {Binding Answer2}" / > 
                            <  单选按钮    ="   a3" 组名  > q"    内容  ="  {Binding Answer3}" / > 
                            <  单选按钮    ="   a4" 组名  > q"    内容  ="  {Binding Answer4}" / > 
                        <  /stackpanel  > 
                    <  /datatemplate  > 
                <  /listbox.itemtemplate  > 
            <  /listbox  > 

            <  按钮    ="  按钮" 高度  > 72"     Horizo​​ntalAlignment   =" 左侧" 保证金   137,529,0,0" 名称   button1"  VerticalAlignment   =" 顶部" 宽度  ="     ="   button1_Click" / > 
        <  /grid  > 
        

    <  /grid  > 

    <!-  显示ApplicationBar用法的示例代码 ->  
    <!-  < phone:phoneapplicationpage.applicationbar>
        < shell:applicationbar isvisible ="True" ismenuenabled ="True" xmlns:shell =#unknown">
            < shell:applicationbariconbutton iconuri ="/Images/appbar_button1.png" text =按钮1"/>
            < shell:applicationbariconbutton iconuri ="/Images/appbar_button2.png" text =按钮2"/>
            < shell:applicationbar.menuitems>
                < shell:applicationbarmenuitem text ="MenuItem 1"/>
                < shell:applicationbarmenuitem text ="MenuItem 2"/>
            </shell:applicationbar.menuitems>
        </shell:应用程序栏>
    </phone:phoneapplicationpage.applicationbar>  ->  

<  /phone:phoneapplicationpage  >  




我要添加是否在C#和xaml中按下单选按钮

 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Net;
使用 System.Windows;
使用使用System.Windows.Controls;
使用 System.Windows.Documents;
使用 System.Windows.Input;
使用 System.Windows.Media;
使用使用System.Windows.Media.Animation;
使用 System.Windows.Shapes;
使用 Microsoft.Phone.Controls;
// 使用System.Xml; 
使用 System.Xml.Linq;
命名空间 kno_your_country
{
   公共 部分  class  cq:PhoneApplicationPage
    {
    // 问题d; 
         int  c =  0 ;
         int  Q =  1 ;
         int  L =  1 ;
        List< int> qid;

                 公共 问题
        {

             int  idi;
             int 级;
            字符串 txt;
            字符串 answer1;
            字符串 answer2;
            字符串 answer3;
            字符串 answer4;
            字符串正确;

            公共  int  Idi
            {
                获取 {返回 idi; }
                 set  {idi =  value ; }
            }
            公共  int 级别
            {
                获取 {返回级别; }
                设置 {级别= ; }
            }

            公共 字符串 Txt
            {
                获取 {返回 txt; }
                设置 {txt = ; }

            }
            公共 字符串 Answer1
            {
                获取 {返回 answer1; }
                设置 {answer1 = ; }
            }
            公共 字符串 Answer2
            {
                获取 {返回 answer2; }
                设置 {answer2 = ; }
            }
            公共 字符串 Answer3
            {
                获取 {返回 answer3; }
                设置 {answer3 = ; }
            }
            公共 字符串 Answer4
            {
                获取 {返回答案4; }
                设置 {answer4 = ; }
            }
            公共 字符串正确
            {
                获取 {返回正确; }
                设置 {正确= ; }
            }
        }

         公共 cq()
        {
            InitializeComponent();
            }
        公共 无效 qview( int  z)
        {
            XDocument loadingCustomData = XDocument.Load(" );
             var  filteredData = 查询 in 中的 loadedCustomData.后代("  + L)
                               其中查询.Attribute("  ).Value == qid [z] .ToString()
                               选择  Questions()
                               {
                                   Txt = query.Attribute(" ).值,
                                   answer1 = query.Attribute(" ).值,
                                   answer2 = query.Attribute(" ).值,
                                   answer3 = query.Attribute(" ).值,
                                   answer4 = query.Attribute(" ).值,
                                   正确= query.Attribute(" ).值

                               };
   listBox.ItemsSource = filteredData;
        }
        公共 无效 LQuiz( int  Li)
        {
            Numbers nbs =  Numbers();
            qid = nbs.RandomNumbers(Li);
        }

        私有 无效 PhoneApplicationPage_Loaded(对象发​​件人,RoutedEventArgs e)
        {
            ApplicationTitle.Text = "  + L;
            LQuiz( 10 );
            qu.Text = "  + Q;
            qview(c);
            Q ++;
            c ++;
        }
       
        私有 无效 button1_Click(对象发​​件人,RoutedEventArgs e)
        {
            如果(L ==  1 )
            {
                如果(c <   5 )
                {

                    qu.Text = "  + Q;
                    ApplicationTitle.Text = "  + L;
                    qview(c);
                    c ++;
                    Q ++;
                    如果(c ==  5 )
                    {
                        
                        c =  0 ;
                        L ++;
                    }

                }
            }
            其他 如果(L ==  2 )
            {
                如果(c <   4 )
                {

                    qu.Text = "  + Q;
                    ApplicationTitle.Text = "  + L;
                    qview(c);
                    c ++;
                    Q ++;
                    如果(c ==  4 )
                    {
                        c =  0 ;
                        L ++;
                    }

                }
            }
            其他 如果(L ==  3 )
            {
                如果(c <   3 )
                {

                    qu.Text = "  + Q;
                    ApplicationTitle.Text = "  + L;
                    qview(c);
                    c ++;
                    Q ++;
                    如果(c ==  3 )
                    {
                        c =  0 ;
                        L ++;
                    }

                }
            }
            其他 如果(L ==  4 )
            {
                如果(c <   2 )
                {

                    qu.Text = "  + Q;
                    ApplicationTitle.Text = "  + L;
                    qview(c);
                    c ++;
                    Q ++;
                    如果(c ==  2 )
                    {
                        c =  0 ;
                        L ++;
                    }

                }
            }
            其他 如果(L ==  5 )
            {
                如果(c <   1 )
                {

                    qu.Text = "  + Q;
                    ApplicationTitle.Text = "  + L;
                    qview(c);
                    c ++;
                    Q ++;
                    如果(c ==  1 )
                    {
                        c =  0 ;
                        L ++;
                    }

                }
            }
            其他 如果(L ==  6 )
            {
                qu.Text = " ;
            }
        }
        }

    数字
    {

        公共列表< int> RandomNumbers( int  max)
        {
            List< int> qid = 列表< int>();
            随机rndNumber =  Random();
             int  number = rndNumber.Next( 1 ,最大值+  1 );
            qid.Add(number);
             int  count =  0 ;
            
            {
                number = rndNumber.Next( 1 ,最大+  1 );
                如果(!qid.包含(数字))
                {
                    qid.Add(number);
                }
                数++;
            }
            同时(计数<  =  10  *最大限度);
            返回 qid;
        }
    }

    }
</  int  >  </  int  >  </  int  >   int  解决方案

好,谢谢,我解决了我的问题
但我需要从

  public   class 中的Correct 获取val 


  public   partial  <phone:phoneapplicationpage xmlns:phone="#unknown">
    x:Class="kno_your_country.cq"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded" DataContext="{Binding}">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <grid x:name="LayoutRoot" removed="Transparent" xmlns:x="#unknown">
        <grid.rowdefinitions>
            <rowdefinition height="Auto" />
            <rowdefinition height="*" />
        </grid.rowdefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <stackpanel x:name="TitlePanel" grid.row="0" margin="12,17,0,28">
            <textblock x:name="ApplicationTitle" text="MY APPLICATION" style="{StaticResource PhoneTextNormalStyle}" />
            <textblock x:name="qu" text="page name" margin="9,-7,0,0" style="{StaticResource PhoneTextTitle1Style}" />
        </stackpanel>

        <!--ContentPanel - place additional content here-->
        <grid x:name="grd" grid.row="1" margin="12,0,12,0">
            <listbox x:name="listBox">
                <listbox.itemtemplate>
                    <datatemplate>
                        <stackpanel margin="10">
                            <textblock text="{Binding Txt}" />
                            <radiobutton name="a1" groupname="q" content="{Binding Answer1}" />
                            <radiobutton name="a2" groupname="q" content="{Binding Answer2}" />
                            <radiobutton name="a3" groupname="q" content="{Binding Answer3}" />
                            <radiobutton name="a4" groupname="q" content="{Binding Answer4}" />
                        </stackpanel>
                    </datatemplate>
                </listbox.itemtemplate>
            </listbox>

            <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="137,529,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
        </grid>
        

    </grid>

    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:phoneapplicationpage.applicationbar>
        <shell:applicationbar isvisible="True" ismenuenabled="True" xmlns:shell="#unknown">
            <shell:applicationbariconbutton iconuri="/Images/appbar_button1.png" text="Button 1" />
            <shell:applicationbariconbutton iconuri="/Images/appbar_button2.png" text="Button 2" />
            <shell:applicationbar.menuitems>
                <shell:applicationbarmenuitem text="MenuItem 1" />
                <shell:applicationbarmenuitem text="MenuItem 2" />
            </shell:applicationbar.menuitems>
        </shell:applicationbar>
    </phone:phoneapplicationpage.applicationbar>-->

</phone:phoneapplicationpage>




I want add is cheked radiobutton or not to the c# and xaml

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
//using System.Xml;
using System.Xml.Linq;
namespace kno_your_country
{
   public partial class cq : PhoneApplicationPage
    {
    //Questions d;
        int c = 0;
        int Q = 1;
        int L = 1;
        List<int> qid;

                 public class Questions
        {

            int idi;
            int level;
            string txt;
            string answer1;
            string answer2;
            string answer3;
            string answer4;
            string correct;

            public int Idi
            {
                get { return idi; }
                set { idi = value; }
            }
            public int Level
            {
                get { return level; }
                set { level = value; }
            }

            public string Txt
            {
                get { return txt; }
                set { txt = value; }

            }
            public string Answer1
            {
                get { return answer1; }
                set { answer1 = value; }
            }
            public string Answer2
            {
                get { return answer2; }
                set { answer2 = value; }
            }
            public string Answer3
            {
                get { return answer3; }
                set { answer3 = value; }
            }
            public string Answer4
            {
                get { return answer4; }
                set { answer4 = value; }
            }
            public string Correct
            {
                get { return correct; }
                set { correct = value; }
            }
        }

         public cq()
        {
            InitializeComponent();
            }
        public void qview(int z)
        {
            XDocument loadedCustomData = XDocument.Load("quiz.xml");
            var filteredData = from query in loadedCustomData.Descendants("question"+L)
                               where query.Attribute("idi").Value == qid[z].ToString()
                               select new Questions()
                               {
                                   Txt = query.Attribute("text").Value,
                                   Answer1 = query.Attribute("answer1").Value,
                                   Answer2 = query.Attribute("answer2").Value,
                                   Answer3 = query.Attribute("answer3").Value,
                                   Answer4 = query.Attribute("answer4").Value,
                                   Correct =  query.Attribute("correct").Value

                               };
   listBox.ItemsSource = filteredData;
        }
        public void LQuiz(int Li)
        {
            Numbers nbs = new Numbers();
            qid = nbs.RandomNumbers(Li);
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            ApplicationTitle.Text = "Level " + L;
            LQuiz(10);
            qu.Text = "Question: " + Q;
            qview(c);
            Q++;
            c++;    
        }
       
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (L == 1)
            {
                if (c < 5)
                {

                    qu.Text = "Question: " + Q;
                    ApplicationTitle.Text = "Level " + L;
                    qview(c);
                    c++;
                    Q++;
                    if (c == 5)
                    {
                        
                        c = 0;
                        L++;
                    }

                }
            }
            else if (L == 2)
            {
                if (c < 4)
                {

                    qu.Text = "Question: " + Q;
                    ApplicationTitle.Text = "Level " + L;
                    qview(c);
                    c++;
                    Q++;
                    if (c == 4)
                    {
                        c = 0;
                        L++;
                    }

                }
            }
            else if (L == 3)
            {
                if (c < 3)
                {

                    qu.Text = "Question: " + Q;
                    ApplicationTitle.Text = "Level " + L;
                    qview(c);
                    c++;
                    Q++;
                    if (c == 3)
                    {
                        c = 0;
                        L++;
                    }

                }
            }
            else if (L == 4)
            {
                if (c < 2)
                {

                    qu.Text = "Question: " + Q;
                    ApplicationTitle.Text = "Level " + L;
                    qview(c);
                    c++;
                    Q++;
                    if (c == 2)
                    {
                        c = 0;
                        L++;
                    }

                }
            }
            else if (L == 5)
            {
                if (c < 1)
                {

                    qu.Text = "Question: " + Q;
                    ApplicationTitle.Text = "Level " + L;
                    qview(c);
                    c++;
                    Q++;
                    if (c == 1)
                    {
                        c = 0;
                        L++;
                    }

                }
            }
            else if (L ==6)
            {
                qu.Text = "The total scor:";
            }   
        }
        }

    class Numbers
    {

        public List<int> RandomNumbers(int max)
        {
            List<int> qid = new List<int>();
            Random rndNumber = new Random();
            int number = rndNumber.Next(1, max + 1);
            qid.Add(number);
            int count = 0;
            do
            {
                number = rndNumber.Next(1, max + 1);
                if (!qid.Contains(number))
                {
                    qid.Add(number);
                }
                count++;
            }
            while (count <= 10 * max);
            return qid;
        }
    }

    }
</int></int></int></int>

解决方案

OK thanks i solve my problem
but i need to get val from Correct in

public class Questions


to

int c;

in

public partial class cq : PhoneApplicationPage


这篇关于我想添加是否被单选按钮选中或不添加到C#和XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆