1、方法一
<UserControl x:Class="SilverlightApplication1.MyListBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWIDth="400">
<GrID x:name="LayoutRoot" Background="White">
<ListBox WIDth="300" Height="200">
<StackPanel x:name="sp">
</StackPanel>
</ListBox>
<@R_404_5554@ WIDth="120" Height="30" margin="50,12,230,258" Content="GetSelectedValue" Click="@R_404_5554@_Click"></@R_404_5554@>
<TextBlock x:name="aaa" Text="123" WIDth="100" Height="30" margin="203,97,258"></TextBlock>
</GrID>
</UserControl>
CheckBox的获取
public partial class MyListBox : UserControl
{
public MyListBox()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
CheckBox cb = new CheckBox();
cb.Content = "cb" + i.ToString();
sp.Children.Add(cb);
}
}
private voID @R_404_5554@_Click(object sender,RoutedEventArgs e)
{
aaa.Text = "";
foreach (CheckBox c in sp.Children)
{
if (c.IsChecked == true)
{
aaa.Text += c.Content.ToString() + ",";
}
}
}
}
Radio@R_404_5554@的获取
public partial class MyListBox : UserControl
{
public MyListBox()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
Radio@R_404_5554@ rb = new Radio@R_404_5554@();
rb.Content = "rbtn" + i.ToString();
sp.Children.Add(rb);
}
}
private voID @R_404_5554@_Click(object sender,RoutedEventArgs e)
{
aaa.Text = "";
foreach (Radio@R_404_5554@ rb in sp.Children)
{
if (rb.IsChecked == true)
{
aaa.Text = rb.Content.ToString();
}
}
方法二:
<GrID x:name="LayoutRoot" Background="White">
<ListBox x:name="MyFeatures" WIDth="300" margin="41,30,59,151">
<ListBox.ItemTemplate>
<DataTemplate>
<Radio@R_404_5554@ Groupname="rbtn" Content="{Binding}" Checked="Radio@R_404_5554@_Checked"></Radio@R_404_5554@>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox x:name="MyCheckBox" WIDth="300" margin="41,155,32">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"></CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:name="aaa" Text="123" Height="30" margin="80,258"></TextBlock>
<@R_404_5554@ WIDth="30" Height="30" margin="358,258,12" Content="aaa" Click="@R_404_5554@_Click"></@R_404_5554@>
</GrID>
}
}
}
List<string> List = new List<string>();
public SilverlightListBox()
{
InitializeComponent();
for (int i = 0; i < 6; i++)
{
List.Add("zhangsan"+i.ToString());
}
MyFeatures.ItemsSource = List;
MyCheckBox.ItemsSource = List;
}
List<string> Listcheck = new List<string>();
private voID Radio@R_404_5554@_Checked(object sender,RoutedEventArgs e)
{
aaa.Text = (sender as Radio@R_404_5554@).Content.ToString();
}
private voID CheckBox_Checked(object sender,RoutedEventArgs e)
{
Listcheck.Add((sender as CheckBox).Content.ToString());
}
private voID CheckBox_Unchecked(object sender,RoutedEventArgs e)
{
Listcheck.Remove((sender as CheckBox).Content.ToString());
}
private voID @R_404_5554@_Click(object sender,RoutedEventArgs e)
{
aaa.Text = "";
for (int i = 0; i < Listcheck.Count; i++)
{
aaa.Text += Listcheck[i].ToString() + ",";
}
}
方法三:
<UserControl x:Class="SilverlightApplication1.ListBoxGrID"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWIDth="400">
<GrID x:name="LayoutRoot" Background="White">
<ScrollVIEwer HorizontalScrollbarVisibility="HIDden" VerticalScrollbarVisibility="auto"
Height="150" MinHeight="150" MaxHeight="150" WIDth="310">
<ScrollVIEwer.Content>
<GrID x:name="Layout" WIDth="auto" MinHeight="30" Height="auto" margin="5">
<GrID.ColumnDeFinitions>
<ColumnDeFinition WIDth="280"></ColumnDeFinition>
</GrID.ColumnDeFinitions>
</GrID>
</ScrollVIEwer.Content>
</ScrollVIEwer>
<@R_404_5554@ x:name="My@R_404_5554@" WIDth="60" Height="30" Content="GetValue" Click="@R_404_5554@_Click" margin="314,250,26,20"></@R_404_5554@>
<TextBlock x:name="aaa" Text="123" Height="30" margin="110,258"></TextBlock>
</GrID>
</UserControl>
public ListBoxGrID()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
RowDeFinition row = new RowDeFinition();
row.Height = new GrIDLength(20);
Layout.RowDeFinitions.Add(row);
CheckBox cb = new CheckBox();
cb.Content = "checkb" + i.ToString();
cb.SetValue(GrID.RowProperty,i);//设置这个才可以正确排列
Layout.Children.Add(cb);
}
}
private voID @R_404_5554@_Click(object sender,RoutedEventArgs e)
{
aaa.Text = "";
foreach (CheckBox c in Layout.Children)
{
if (c.IsChecked == true)
{
aaa.Text += c.Content.ToString() + ",";
}
}
}
public ListBoxGrID()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
RowDeFinition row = new RowDeFinition();
row.Height = new GrIDLength(20);
Layout.RowDeFinitions.Add(row);
Radio@R_404_5554@ rb = new Radio@R_404_5554@();
rb.Content = "rbtn" + i.ToString();
rb.SetValue(GrID.RowProperty,i);
Layout.Children.Add(rb);
}
}
private voID @R_404_5554@_Click(object sender,RoutedEventArgs e) { aaa.Text = ""; foreach (Radio@R_404_5554@ c in Layout.Children) { if (c.IsChecked == true) { aaa.Text += c.Content.ToString() + ","; } } }
总结以上是内存溢出为你收集整理的Silverlight内CheckBox控件与RadioButton控件的赋值与取值全部内容,希望文章能够帮你解决Silverlight内CheckBox控件与RadioButton控件的赋值与取值所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)