WPF DataGrid绑定一个组合列
WPF DataGrid绑定一个组合列
前台:
<Page.Resources>
<local:InfoConverter x:Key="converter"></local:InfoConverter>
</Page.Resources>
<DataGridTextColumn>
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource converter}">
<Binding Path="Volume"></Binding>
<Binding Path="Unit"></Binding>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
后台:
public class InfoConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string volume = values[0].ToString();
string unit = values[1].ToString();
return volume + unit ;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}