对于WPFRadioButton的绑定感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍wpfradiobutton绑定数据,并为您提供关于android–取消选中RadioButton的–替代方
对于WPF RadioButton的绑定感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍wpf radiobutton绑定数据,并为您提供关于android – 取消选中RadioButton的 – 替代方法、Android 自定义RadioButton的样式、c# – WPF:如何让Radiobuttons显示为ToggleButtons的水平行、c# – 与RadioButton的绑定问题的有用信息。
本文目录一览:- WPF RadioButton的绑定(wpf radiobutton绑定数据)
- android – 取消选中RadioButton的 – 替代方法
- Android 自定义RadioButton的样式
- c# – WPF:如何让Radiobuttons显示为ToggleButtons的水平行
- c# – 与RadioButton的绑定问题
WPF RadioButton的绑定(wpf radiobutton绑定数据)
1. 枚举类
public enum EnumDataTypes
{
Simulation,
Test
}
2. 枚举型与布尔型的转换
public class EnumToBooleanConverter : IValueConverter
{
/// <inheritdoc/>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? false : value.Equals(parameter);
}
/// <inheritdoc/>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null && value.Equals(true) ? parameter : Binding.DoNothing;
}
}
3. 控件XAML的代码
<Window.Resources>
<pv:EnumToBooleanConverter x:Key="EnumBoolConverter" />
</Window.Resources>
<RadioButton Grid.Column="0" Content="仿真" VerticalAlignment="Center"
Margin="10 5 0 5"
IsChecked="{Binding Path=SelectedDatabase.DataType,
Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static pv:EnumDataTypes.Simulation}}"/>
<RadioButton Grid.Column="1" Content="试验" VerticalAlignment="Center"
Margin="20 5 0 5"
IsChecked="{Binding Path=SelectedDatabase.DataType,
Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static pv:EnumDataTypes.Test}}"/>
android – 取消选中RadioButton的 – 替代方法
解决方法
RadioGroup radioGroup; RadioButton radioButton1; RadioButton radioButton2; RadioButton radioButton3; boolean hack = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); radioGroup = (RadioGroup) findViewById(R.id.rg); radioButton1 = (RadioButton) findViewById(R.id.r1); radioButton2 = (RadioButton) findViewById(R.id.r2); radioButton3 = (RadioButton) findViewById(R.id.r3); OnClickListener radioClickListener = new OnClickListener() { public void onClick(View v) { if (v.getId() == radioGroup.getCheckedRadioButtonId() && hack) { radioGroup.clearCheck(); } else { hack = true; } } }; OnCheckedchangelistener radioCheckchangelistener = new OnCheckedchangelistener() { @Override public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) { hack = false; } }; radioButton1.setonCheckedchangelistener(radioCheckchangelistener); radioButton2.setonCheckedchangelistener(radioCheckchangelistener); radioButton3.setonCheckedchangelistener(radioCheckchangelistener); radioButton1.setonClickListener(radioClickListener); radioButton2.setonClickListener(radioClickListener); radioButton3.setonClickListener(radioClickListener); }
好的,现在我已经更新了.这应该是Philipz
Android 自定义RadioButton的样式
我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式。
最近用到 RadioButton,利用xml修改android:background="@drawable/button_drawable",其中 button_drawable为自己定义的.xml文件(res/drawable文件下),但是不成功,到网上查找,也没有正确的说法,我就开始自己尝试,最后做好了。
其实方法很简单,同样在res/drawable新建radiobutton.xml如下
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/check" ;/> <item android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/checknull" ;/> </selector>
check和checknull分别为选中和位选中的图片。
然后在你的布局文件中,RadioButton 布局
设置android:button = "@drawable/radiobutton",就可以了!
前后图片对比如下:
就是这么简单,所以学习是自己摸索的!Android的控件真的很强大的!
c# – WPF:如何让Radiobuttons显示为ToggleButtons的水平行
<Style x:Key="{x:Type RadioButton}" targettype="{x:Type RadioButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
但是,这将显示一列ToggleButtons,而不是一行.
你知道一个简单的方法吗?
非常感谢!
解决方法
<StackPanel Orientation="Horizontal"> <RadioButton Content="1"/> <RadioButton Content="2"/> <RadioButton Content="3"/> </StackPanel >
c# – 与RadioButton的绑定问题
我想要完成的是将两个布尔值绑定到两个RadioButtons的IsChecked属性,共享相同的GroupName(因此一次只检查一个).
我面临的问题是,当ContentPresenter的内容即将更改时(通过绑定到ComboBox的SelectedItem),当前内容接收对Property-setter的调用,该属性具有相同属性的值,但是从视图中即将成为新内容的模型. (!)最终结果是视图模型发生了变化,尽管没有点击绑定到相关属性的RadioButton.
我把together a sample app显示出来了.要重现,请运行该应用并按照以下步骤操作:
>在组合框中选择“一个”=>检查MyPropery,MyProperty2不是.
>在组合框中选择“三个”=>检查MyPropery,MyProperty2不是.
>选择“三个”时,单击MyProperty2 =>检查MyProperty2(也在调试输出窗口中显示)
>在组合框中选择“一个”=>检查MyPropery,MyProperty2不是.请注意调试窗口如何在此处显示对象“Three”的MyProperty2如何设置为false
>在组合框中选择“三个”=>现在都没有检查Radiobuttons(由于#4).
如果在#3和#4之间,首先在组合框中选择“Two”以使ContentPresenter显示另一个视图(通过DataTemplate选择),问题不会出现!?
有人可以解释为什么在ContentPresenter交换视图时,在第4步设置属性,以及可以采取哪些措施?
解决方法
当你切换到Two并返回到Three时,WPf将简单地从缓存中重新绘制项目,但是切换到One并返回到Three,它会更改对象后面的DataContext.我认为这是导致问题的原因,因为它似乎在删除DataContext之前清除了第二个RadioButton IsChecked,因此最终结果是Property2被设置为false.如果One和Three都选择了第二个单选按钮,则不会发生这种情况.
通常在这种情况下,我将使VM包含ObservableCollection< T> Items和一个int Selectedindex.然后我将使用ListBox绘制UI,该ListBox已被覆盖以使用RadioButtons作为项目.这样,一次只能选择一个项目,并且只有一个属性用于存储所选项目.
今天关于WPF RadioButton的绑定和wpf radiobutton绑定数据的介绍到此结束,谢谢您的阅读,有关android – 取消选中RadioButton的 – 替代方法、Android 自定义RadioButton的样式、c# – WPF:如何让Radiobuttons显示为ToggleButtons的水平行、c# – 与RadioButton的绑定问题等更多相关知识的信息可以在本站进行查询。
本文标签: