2

is there a solution to bind multiple properties to my ClipboardBinding. I tried the following code but this didnt work:

<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>

i'd appreciate adivce for a workaround too. Please help

4

1 回答 1

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>
于 2013-03-14T17:38:54.920 回答