WPF DataGrid ClipboardBinding Multibinding可能吗?

时间:2013-03-14 16:17:37

标签: wpf multibinding

是否有解决方案将多个属性绑定到我的ClipboardBinding。 我尝试了以下代码,但这没有用:

<DataGridTemplateColumn CanUserSort="True" SortMemberPath="Characteristic.Area.Name.ActualTranslation" MinWidth="120" >
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Margin="5,0,5,0">
                <TextBlock Text="{Binding Characteristic.Area.Name.ActualTranslation}"></TextBlock>
                <TextBlock Text="  "></TextBlock>
                <TextBlock Text="{Binding AreaItem.Value}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{lex:Loc Area}"></TextBlock>
        </DataTemplate>
    </DataGridTemplateColumn.HeaderTemplate>
    <DataGridTemplateColumn.ClipboardContentBinding>
        <!-- TODO: ClipboardBinding Area -->
        <MultiBinding  StringFormat="{}{0} {1}">
            <Binding Path="Characteristic.Area.Name.ActualTranslation" />
            <Binding Path="AreaItem.Value" />
        </MultiBinding>
    </DataGridTemplateColumn.ClipboardContentBinding>
</DataGridTemplateColumn>

我也很感激为解决方法而努力。 请帮忙

1 个答案:

答案 0 :(得分:4)

您应该使用转换器(msdn)。

class StringFormatConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return string.Format(parameter.ToString(), values);
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

XAML:

<DataGridTemplateColumn.ClipboardContentBinding>      
    <MultiBinding  
        ConverterParameter=" {0} {1}"
        Converter="{StaticResource conString}">
        <Binding Path="Characteristic.Area.Name.ActualTranslation" />
        <Binding Path="AreaItem.Value" />
    </MultiBinding>
</DataGridTemplateColumn.ClipboardContentBinding>