我正在尝试将 ListView 或 GridView 作为 ConverterParameter 传递但是,在 Converter 例程中,参数以类型字符串的形式出现
下面是 XAML 列表视图和 Converter 类的一部分。
非常感谢任何帮助。谢谢!!!
<ListView Name="SeqDtStDataListView1" Grid.Row="1"
DataContext="{Binding Path=DisplayDT[0], Converter ={StaticResource
CNVToColumn},ConverterParameter=?????}"
VerticalContentAlignment="Stretch" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
SelectionChanged="SEQDatalistview_SelectionChanged" Margin="5">
<ListView.View >
<GridView x:Name="SeqDtStDataGridView1"/>
</ListView.View>
</ListView>
转换器:
namespace MFTest.Converters
{
public class CNVToColumn : IValueConverter
{
public object Convert(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
DataTable dt = (DataTable)value;
GridView GV = (GridView)parameter; <========= fail here ===========
if (dt != null && GV != null)
foreach (var colum in dt.Columns) // Binding the Columns
{
DataColumn dc = (DataColumn)colum;
GridViewColumn column = new GridViewColumn();
column.DisplayMemberBinding = new Binding(dc.ColumnName);
column.Header = dc.ColumnName;
GV.Columns.Add(column);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}