8,756
社区成员




<Combobox ItemSource={Binding List,Convert={StaticSource ListConvert},ConvertParameter={Binding List}}>
[/quote]
这里的List是什么?<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfTest"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:MyConverter x:Key="myC"/>
</Window.Resources>
<Grid>
<ComboBox HorizontalAlignment="Left" Margin="50,43,0,0" VerticalAlignment="Top" Width="120" x:Name="cmbMultiple"/>
<ComboBox HorizontalAlignment="Left" Margin="50,172,0,0" VerticalAlignment="Top" Width="120" x:Name="cmbValueList" ItemsSource="{Binding Text, Converter={StaticResource myC}, ElementName=cmbMultiple}" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
namespace WpfTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
cmbMultiple.ItemsSource = new List<Int32> { 1, 2, 3, 4 };
}
}
[ValueConversion(typeof(String), typeof(List<Int32>))]
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
String str = value.ToString();
Int32 v = 0;
if (Int32.TryParse(str, out v)) {
List<Int32> result = new List<int> { 4, 3, 2, 1 };
for (Int32 i = 0; i < result.Count; i++) {
result[i] = result[i] * v;
}
return result;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
<Combobox ItemSource={Binding List,Convert={StaticSource ListConvert},ConvertParameter={Binding List}}>