[英]Using a Radio Button Group binding value from sql collection
Good morning,早上好,
So this is basically like a ticket system, you fill in a ticket and then someone with higher permissions will be able to go in and open that ticket.所以这基本上就像一个票证系统,你填写一张票证,然后具有更高权限的人将能够进入 go 并打开该票证。 When they open that ticket I got everything else binding besides the
RadioButtonGroup
.当他们打开那张票时,我得到了除
RadioButtonGroup
之外的所有其他绑定。 All the data is fetched from SQL and stored into a collection from a class using SqlReader
as you see below the textboxes are getting their binded value所有数据均从 SQL 获取并使用
SqlReader
从 class 存储到集合中,如下所示,文本框正在获取它们的绑定值
example of radio button groups单选按钮组示例
To quickly explain what I am trying to do.快速解释我想要做什么。 I would like to have this group of radio buttons that when I select a
RadioButton
and press save I can save the value into the SQL.我想要这组单选按钮,当我 select 一个
RadioButton
按钮并按保存时,我可以将值保存到 SQL 中。 Then I would like to be able to bind that value and have it binded when someone pulls up that ticket like the textboxes然后我希望能够绑定该值并在有人像文本框一样拉起该票时将其绑定
XAML XAML
<WrapPanel Margin="0,10,0,0" VerticalAlignment="Top" Height="20">
<RadioButton Content="Domestic"
GroupName="RadioButtonGroup"
IsChecked="{Binding RadioButtonSource, Converter={StaticResource EnumBooleanConverter}, ConverterParameter={x:Static model:RadioButtonSource.Domestic}}" />
<RadioButton Content="Japan"
GroupName="RadioButtonGroup"
IsChecked="{Binding RadioButtonSource, Converter={StaticResource EnumBooleanConverter}, ConverterParameter={x:Static model:RadioButtonSource.Japan}}" />
<RadioButton Content="House"
GroupName="RadioButtonGroup"
IsChecked="{Binding RadioButtonSource, Converter={StaticResource EnumBooleanConverter}, ConverterParameter={x:Static model:RadioButtonSource.House}}" />
</WrapPanel>
Class Class
Source = reader.GetInt32("source");
public int _Source;
public int Source
{
get { return _Source; }
set { _Source = value; RaisePropertyChanged("source"); }
}
Converter转换器
public class EnumBooleanConverter : MarkupConverter
{
protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(parameter);
}
protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value == true ? parameter : Binding.DoNothing;
}
}
Then I also made this enum for it in it's own class然后我还在它自己的 class 中为它制作了这个枚举
public enum RadioButtonSource
{
Domestic,
Japan,
House
}
then the SQL to insert a new ticket然后 SQL 插入新票
cmd.Parameters.AddWithValue("@entrydate", Date);
cmd.Parameters.AddWithValue("@source", Source);
cmd.Parameters.AddWithValue("@prodcell", Prodcell);
cmd.Parameters.AddWithValue("@workcenter", Workcenter);
cmd.Parameters.AddWithValue("@supplier", Supplier);
cmd.Parameters.AddWithValue("@createdby", Createdby);
cmd.Parameters.AddWithValue("@department", Dept);
cmd.Parameters.AddWithValue("@deptdesc", deptdesc);
cmd.Parameters.AddWithValue("@reviewedby", Reviewedby);
cmd.Parameters.AddWithValue("@shift", Shift);
cmd.Parameters.AddWithValue("@parts", SerializedParts);
cmd.Parameters.AddWithValue("@problem", problemRB);
cmd.Parameters.AddWithValue("@problemdesc", Problemdesc);
cmd.Parameters.AddWithValue("@supplotnum", Supplierlotnum);
everything works but Source
一切正常,但
Source
Good morning,早上好,
So this is basically like a ticket system, you fill in a ticket and then someone with higher permissions will be able to go in and open that ticket.所以这基本上就像一个票证系统,你填写一张票证,然后具有更高权限的人将能够进入 go 并打开该票证。 When they open that ticket I got everything else binding besides the
RadioButtonGroup
.当他们打开那张票时,我得到了除
RadioButtonGroup
之外的所有其他绑定。 All the data is fetched from SQL and stored into a collection from a class using SqlReader
as you see below the textboxes are getting their binded value所有数据均从 SQL 获取并使用
SqlReader
从 class 存储到集合中,如下所示,文本框正在获取它们的绑定值
example of radio button groups单选按钮组示例
To quickly explain what I am trying to do.快速解释我想要做什么。 I would like to have this group of radio buttons that when I select a
RadioButton
and press save I can save the value into the SQL.我想要这组单选按钮,当我 select 一个
RadioButton
按钮并按保存时,我可以将值保存到 SQL 中。 Then I would like to be able to bind that value and have it binded when someone pulls up that ticket like the textboxes然后我希望能够绑定该值并在有人像文本框一样拉起该票时将其绑定
XAML XAML
<WrapPanel Margin="0,10,0,0" VerticalAlignment="Top" Height="20">
<RadioButton Content="Domestic"
GroupName="RadioButtonGroup"
IsChecked="{Binding RadioButtonSource, Converter={StaticResource EnumBooleanConverter}, ConverterParameter={x:Static model:RadioButtonSource.Domestic}}" />
<RadioButton Content="Japan"
GroupName="RadioButtonGroup"
IsChecked="{Binding RadioButtonSource, Converter={StaticResource EnumBooleanConverter}, ConverterParameter={x:Static model:RadioButtonSource.Japan}}" />
<RadioButton Content="House"
GroupName="RadioButtonGroup"
IsChecked="{Binding RadioButtonSource, Converter={StaticResource EnumBooleanConverter}, ConverterParameter={x:Static model:RadioButtonSource.House}}" />
</WrapPanel>
Class Class
Source = reader.GetInt32("source");
public int _Source;
public int Source
{
get { return _Source; }
set { _Source = value; RaisePropertyChanged("source"); }
}
Converter转换器
public class EnumBooleanConverter : MarkupConverter
{
protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(parameter);
}
protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value == true ? parameter : Binding.DoNothing;
}
}
Then I also made this enum for it in it's own class然后我还在它自己的 class 中为它制作了这个枚举
public enum RadioButtonSource
{
Domestic,
Japan,
House
}
then the SQL to insert a new ticket然后 SQL 插入新票
cmd.Parameters.AddWithValue("@entrydate", Date);
cmd.Parameters.AddWithValue("@source", Source);
cmd.Parameters.AddWithValue("@prodcell", Prodcell);
cmd.Parameters.AddWithValue("@workcenter", Workcenter);
cmd.Parameters.AddWithValue("@supplier", Supplier);
cmd.Parameters.AddWithValue("@createdby", Createdby);
cmd.Parameters.AddWithValue("@department", Dept);
cmd.Parameters.AddWithValue("@deptdesc", deptdesc);
cmd.Parameters.AddWithValue("@reviewedby", Reviewedby);
cmd.Parameters.AddWithValue("@shift", Shift);
cmd.Parameters.AddWithValue("@parts", SerializedParts);
cmd.Parameters.AddWithValue("@problem", problemRB);
cmd.Parameters.AddWithValue("@problemdesc", Problemdesc);
cmd.Parameters.AddWithValue("@supplotnum", Supplierlotnum);
everything works but Source
一切正常,但
Source
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.