【问题标题】:UWP style setter value binding not working code behindUWP 样式设置器值绑定不工作代码后面
【发布时间】:2021-10-24 14:59:38
【问题描述】:

我有一个具有动态列数的动态数据网格。

在我的循环中添加一列代码:

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

这个数据网格单元工具提示的结果是:

当我将样式设置器值更改为常量时,一切正常:

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

如何在样式设置器值中使用绑定?

【问题讨论】:

    标签: c# uwp


    【解决方案1】:

    SetterValue 应设置为(数据绑定)Tooltip 而不是 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));
    

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 2012-01-21
      • 2019-03-07
      相关资源
      最近更新 更多