MultiBinding 实现动态传入参数 Combox选择性显示数据
2013-08-12 15:58
387 查看
XAML:
<Grid x:Name="LayoutRoot">
<ComboBox HorizontalAlignment="Left" Text="Name" Name="CbBz" Margin="31,171,0,0" VerticalAlignment="Top" Width="120"/>
<ComboBox x:Name="Cm" HorizontalAlignment="Left" Margin="31,214,0,0" VerticalAlignment="Top" Width="120">
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource MulitConvert}">
<Binding />
<Binding ElementName="CbBz" Path="Text"/>
</MultiBinding>
</ComboBox.ItemsSource>
</ComboBox>
</Grid>
CS:
public class MulitConvert : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
List<Student> Lt = (List<Student>)values[0];
switch (values[1].ToString())
{
case "Name":
var v = from n in Lt select n.Name;
return v;
case "Age":
return from n in Lt select n.Age;
}
return new object();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
List<Student> Lt = new List<Student>();
CbBz.Items.Add("Name");
CbBz.Items.Add("Age");
Student S1 = new Student();
S1.Name = "张飞";
S1.Age = 1000;
Student S2 = new Student();
S2.Name = "赵云";
S2.Age = 2000;
Student S3 = new Student();
S3.Name = "刘备";
S3.Age = 3000;
Lt.Add(S1);
Lt.Add(S2);
Lt.Add(S3);
LayoutRoot.DataContext = Lt;
<Grid x:Name="LayoutRoot">
<ComboBox HorizontalAlignment="Left" Text="Name" Name="CbBz" Margin="31,171,0,0" VerticalAlignment="Top" Width="120"/>
<ComboBox x:Name="Cm" HorizontalAlignment="Left" Margin="31,214,0,0" VerticalAlignment="Top" Width="120">
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource MulitConvert}">
<Binding />
<Binding ElementName="CbBz" Path="Text"/>
</MultiBinding>
</ComboBox.ItemsSource>
</ComboBox>
</Grid>
CS:
public class MulitConvert : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
List<Student> Lt = (List<Student>)values[0];
switch (values[1].ToString())
{
case "Name":
var v = from n in Lt select n.Name;
return v;
case "Age":
return from n in Lt select n.Age;
}
return new object();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
List<Student> Lt = new List<Student>();
CbBz.Items.Add("Name");
CbBz.Items.Add("Age");
Student S1 = new Student();
S1.Name = "张飞";
S1.Age = 1000;
Student S2 = new Student();
S2.Name = "赵云";
S2.Age = 2000;
Student S3 = new Student();
S3.Name = "刘备";
S3.Age = 3000;
Lt.Add(S1);
Lt.Add(S2);
Lt.Add(S3);
LayoutRoot.DataContext = Lt;
相关文章推荐
- GridView 动态添加模板列并绑定数据 实现从外部直接传入控件 和 绑定字段参数
- qt外部数据传入实现动态的折线图绘制
- Django向Highcharts图表发送数据并用模板语言实现动态显示
- JS实现点击参数面板按钮显示或隐藏数据
- 实现动态页面传值 options动态显示数据
- ajax+jquery+flea+smarty实现了通过选择下拉列表动态显示相应的数据
- 关于dorado框架datatable处的右键菜单无法根据具体数据实现动态分别显示不同菜单的解决方法
- [安卓] 9、线程、VIEW、消息实现从TCP服务器获取数据动态加载显示
- python中plot实现即时数据动态显示方法
- JS实现点击参数面板按钮显示或隐藏数据
- Highcharts AJAX JSON JQuery 实现动态数据交互显示图表 柱形图
- qt外部数据传入实现动态的折线图绘制
- 用java实现动态菜单的显示--数据库实现与菜单参数初始化
- Highcharts AJAX JSON JQuery 实现动态数据交互显示图表 柱形图
- ArcEngine下动态数据的实现显示——概念及接口介绍
- EditText+ListView实现从动态显示数据库数据
- jQuery实现动态显示select下拉列表数据的方法
- FusionChart实现柱状图、饼状图的动态数据显示
- FusionChart实现柱状图、饼状图的动态数据显示 附Demo