无法在WPF的ContentPresenter中显示线形状。

huangapple go评论77阅读模式
英文:

Not able to show Line shape on ContentPresenter in wpf

问题

我正在尝试在WPF的Content Presenter上显示不同的形状,我能够显示矩形,但是线条对象没有被填充,有人可以帮助我吗?

Line r = new Line();
r.SetValue(Canvas.TopProperty, 50.0);
r.SetValue(Canvas.LeftProperty, 10.0);
r.X1 = 50;
r.Y1 = 50;
r.X2 = 150;
r.Y2 = 150;
r.Width = 200;
r.StrokeThickness = 5.0;
r.Fill = new SolidColorBrush(Colors.Green);
ContentComponent.Content = r;
英文:

I am trying to display different shapes on Content Presenter in wpf, I am able to show Rectangle but Line object is not getting populated, Can anyone help me with this

 Line r = new Line();
        r.SetValue(Canvas.TopProperty, 50.0);
        r.SetValue(Canvas.LeftProperty, 10.0);
        r.X1 = 50;
        r.Y1 = 50;
        r.X2 = 150;
        r.Y2 = 150;
        r.Width = 200;
        r.StrokeThickness = 5.0;
        r.Fill = new SolidColorBrush(Colors.Green);
        ContentComponent.Content = r;

答案1

得分: 1

你应该将Stroke属性设置为一个Brush

r.Stroke = Brushes.Green;

请注意,没有必要使用new SolidColorBrush(Colors.Green)创建新的绿色刷子,而可以使用Brushes类的静态Green属性。

英文:

You should set the Stroke property to a Brush:

r.Stroke = Brushes.Green;

Note that there is no reason to create a new green brush using new SolidColorBrush(Colors.Green) instead of using the static Green property of the Brushes class.

huangapple
  • 本文由 发表于 2020年1月3日 18:27:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576910.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定