【问题标题】:WPF Binding brush generates marshalling errorWPF 绑定画笔生成编组错误
【发布时间】:2020-05-29 14:31:45
【问题描述】:

我很困惑,因为在运行时我收到了这个错误: 应用程序调用了为不同线程编组的接口。 (0x8001010E (RPC_E_WRONG_THREAD))'

我有一个 on 对象:

            <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock
                Grid.Column="0"
                FontFamily="Segoe MDL2 Assets"
                Foreground="{Binding ImageColor, Mode=OneWay}"
                Text="{Binding ImageSrc, Mode=OneWay}" />
            <TextBlock
                Grid.Column="1"
                VerticalAlignment="Center"
                Text="{Binding VisitDescr, Mode=OneWay}" />
        </Grid>

在我的班级里

    public string ImageSrc
    {
        get
        {
            switch (Type)
            {
                case "c1":
                    return "\xE8B9";
                    break;
                default:
                    return "\xE8A5";
                    break;
            }
        }
    }

    public Brush ImageColor
    {
        get
        {
            switch (Type)
            {
                case "c1":
                    return new SolidColorBrush(Colors.MediumOrchid);
                    break;
                case "c2":
                    return new SolidColorBrush(Colors.DarkOrchid);
                default:
                    return new SolidColorBrush(Colors.Red);
                    break;
            }
        }
    }

图像返回时没有任何错误,但颜色会产生错误并且不会更改。

我怎么可能收到编组错误?

【问题讨论】:

    标签: wpf data-binding colors runtime-error marshalling


    【解决方案1】:

    我找到了问题......它正在使用工作库。 我已将其更新为:

    using System.Windows.Media;
    

    现在正在工作。 但是为什么会出现 Marshalling 而不是类型转换错误呢?

    【讨论】:

      猜你喜欢
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      相关资源
      最近更新 更多