小编ant*_*ord的帖子

TextBlock中的内联对象,TextTrimming = CharacterEllipsis或WordEllipsis

如果您运行此代码并最小化/最大化窗口的宽度

<TextBlock TextTrimming="WordEllipsis" >
    <Run Text="I want that this rectangle will be placed "/>
    <Rectangle Fill="Black" Width="20" Height="10" />
    <Run Text=" here when I minimize width of the window"/>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

你会看到Rectange会转移到左侧. 在此输入图像描述 在此输入图像描述

是WPF中的错误吗?

wpf textblock texttrimming

10
推荐指数
1
解决办法
1146
查看次数

将隐式转换运算符与switch结合使用

不明确的行为,如果我声明类型:

struct Token
{
    public static implicit operator int(Token x)
    {
        return 0;
    }

    public static implicit operator string(Token x)
    {
        return "";
    }
}
Run Code Online (Sandbox Code Playgroud)

我们有两个隐式转换.如果我使用工作文件

var t = new Token();

if (t == "123")
{

}
Run Code Online (Sandbox Code Playgroud)

CS0151:开关表达式或大小写标签必须是bool,char,string,integral,enum或相应的可空类型

如果我使用:

switch (t)
{
    case "123" :
    {
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

但如果我删除int隐式转换,则错误消失.

struct Token
{
    public static implicit operator string(Token x)
    {
        return "";
    }
}
Run Code Online (Sandbox Code Playgroud)

它是编译器中的错误还是正确的行为?

c#

3
推荐指数
2
解决办法
283
查看次数

标签 统计

c# ×1

textblock ×1

texttrimming ×1

wpf ×1