0
votes

I have a dinamic datagrid with dinamic number of columns.

Add one column code in my cycle:

CValueConverter valueConverter = new CValueConverter()
{
    Field = fieldDg
};

Style textStyle = new Style(typeof(TextBlock));
textStyle.Setters.Add(new Setter(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis));
textStyle.Setters.Add(
    new Setter(
        ToolTipService.ToolTipProperty,
        new Binding
        {
            Path = new PropertyPath("[" + cmnIndex.ToString() + "]"),
            Converter = valueConverter
        }));
                                
this.FormListDg.Columns.Add(new DataGridTextColumn()
{
    Header = fieldDg.Name,
    HeaderStyle = this.GetHeaderStyle(fieldDg.Color),
    CellStyle = this.GetCellStyle(fieldDg.Color),
    CanUserSort = true,
    MaxWidth = 300,
    Binding = new Binding
    {
        Path = new PropertyPath("[" + cmnIndex.ToString() + "]"),
        Converter = valueConverter
    },
    ElementStyle = textStyle
});

cmnIndex++;

The result of this datagrid cell tooltip is:

enter image description here

When I change the style setter value to constant, everything is works fine:

    textStyle.Setters.Add(
    new Setter(
        ToolTipService.ToolTipProperty,
        "VALAMI"));

enter image description here

How can I use binding in style setter value?

1

1 Answers

1
votes

The Value of the Setter should to be set to a (data-bound) Tooltip and not Binding:

ToolTip tt = new ToolTip();
tt.SetBinding(ContentControl.ContentProperty, new Binding
{
    Path = new PropertyPath("[" + cmnIndex.ToString() + "]"),
    Converter = valueConverter
});

textStyle.Setters.Add(
    new Setter(
        ToolTipService.ToolTipProperty,
        tt));