英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论