WPF数据网格剪贴板绑定



是否有一个解决方案来绑定多个属性到我的clipboarbinding。我尝试了以下代码,但这不起作用:

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

我也很感激你的建议。请帮助

你应该使用converter (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>

相关内容

  • 没有找到相关文章

最新更新