wpf radiobuttonlist实现
来源:互联网 发布:cg制作软件 编辑:程序博客网 时间:2024/05/22 16:38
1、创建类:MulitBooleanConverter
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Data;namespace ScreenLock{ class MulitBooleanConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int serviceParameter = int.Parse(parameter.ToString()); bool isOnservice = (bool)value; bool result = false; switch (serviceParameter) { case 0: result = true && isOnservice; break; case 1: result = !isOnservice; break; } return result; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int serviceParameter = int.Parse(parameter.ToString()); bool isOnservice = (bool)value; bool result = false; switch (serviceParameter) { case 0: result = true && isOnservice; break; case 1: result = false && isOnservice; break; } return value; } #endregion }}
2、界面RadioButton
<Window x:Class="ScreenLock.RadioButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="RadioButton" Height="300" Width="300" xmlns:local="clr-namespace:ScreenLock" > <Window.Resources> <local:MulitBooleanConverter x:Key="boolConverter"></local:MulitBooleanConverter> <Style x:Key="HorizontalRadioButtonListStyle" TargetType="ListBox"> <Style.Resources> <Style TargetType="ListBoxItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Grid Margin="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <RadioButton IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" /> <ContentPresenter Grid.Column="1" Margin="2,0,0,0" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Style.Resources> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <WrapPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="BorderThickness" Value="0" /> <Setter Property="Background" Value="Transparent" /> </Style> </Window.Resources> <Grid> <ListBox Style="{StaticResource HorizontalRadioButtonListStyle}" x:Name="list1" SelectionChanged="list1_SelectionChanged"> <ListBox.Items> <ListBoxItem IsSelected="{Binding xxx,Converter={StaticResource boolConverter},ConverterParameter=0}" Content="在线" ></ListBoxItem> <ListBoxItem IsSelected="{Binding xxx,Converter={StaticResource boolConverter},ConverterParameter=1}" Content="离线"></ListBoxItem> <ListBoxItem IsSelected="{Binding xxx,Converter={StaticResource boolConverter},ConverterParameter=0}" Content="离线llll"></ListBoxItem> </ListBox.Items> </ListBox> </Grid></Window>
3、后台选中事件
private void list1_SelectionChanged(object sender, SelectionChangedEventArgs e) { MessageBox.Show(((ListBoxItem)list1.SelectedItem).Content.ToString()); }
0 0
- wpf radiobuttonlist实现
- WPF and SL RadioButtonList Tip
- RadioButtonList
- RadioButtonList
- RadioButtonList
- 实现RadioButtonList自定义WinForm控件
- MVC 自己实现RadioButtonList方法
- 2个RadioButtonList之间实现单选
- 如何使用radiobuttonlist实现下面的功能
- 用Datalist配合RadioButtonList实现单项选择题
- MVC通过扩展HtmlHelper实现RadioButtonList
- 如何利用RadioButtonList实现datagrid列的单选
- 如何利用RadioButtonList实现datagrid列的单选
- 如何利用RadioButtonList实现datagrid列的单选
- 实现多个RadioButtonList的互斥功能
- 实现多个RadioButtonList的互斥功能
- 自定义RadioButtonList
- RadioButtonList专题
- Linux的命令及全称
- 编写代码,演示多个字符从两端移动,向中间汇聚。
- C语言基础 检验输入的字符是不是字母
- vs2015将网站发布到mircosoft azure上
- leetcode.365. Water and Jug Problem
- wpf radiobuttonlist实现
- 小玩文件
- 身份证号码验证算法
- Android源码解析ViewGroup的touch事件分发机制
- 一个简单的弹球游戏
- C语言基础 按位运算符 按位与,或,非,左移,右移
- UNIX学习笔记
- [疯狂Java]面向对象:初始化块、初始化代码、初始化顺序
- 研发工具使用笔记