-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPptSlideControl.axaml.cs
More file actions
117 lines (103 loc) · 3.7 KB
/
PptSlideControl.axaml.cs
File metadata and controls
117 lines (103 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using System.Collections.Generic;
namespace ShowWrite
{
public partial class PptSlideControl : UserControl
{
public static readonly StyledProperty<Stretch> StretchProperty =
AvaloniaProperty.Register<PptSlideControl, Stretch>(nameof(Stretch), Stretch.Uniform);
public Stretch Stretch
{
get { return GetValue(StretchProperty); }
set { SetValue(StretchProperty, value); }
}
public PptSlideControl()
{
InitializeComponent();
}
public void LoadSlide(PptService.PptSlide slide)
{
// 清空现有内容
SlideGrid.Children.Clear();
// 设置背景颜色
if (!string.IsNullOrEmpty(slide.BackgroundColor))
{
if (Avalonia.Media.Color.TryParse(slide.BackgroundColor, out var color))
{
SlideGrid.Background = new Avalonia.Media.SolidColorBrush(color);
}
}
else
{
// 默认背景为白色
SlideGrid.Background = Avalonia.Media.Brushes.White;
}
// 添加幻灯片元素
foreach (var shape in slide.Shapes)
{
Control shapeControl = CreateShapeControl(shape);
if (shapeControl != null)
{
// 设置位置和大小
shapeControl.Margin = new Thickness(shape.X, shape.Y, 0, 0);
shapeControl.Width = shape.Width;
shapeControl.Height = shape.Height;
// 添加到网格
SlideGrid.Children.Add(shapeControl);
}
}
}
private Control CreateShapeControl(PptService.PptShape shape)
{
if (!string.IsNullOrEmpty(shape.Text))
{
// 创建文本框
var textBlock = new TextBlock
{
Text = shape.Text,
TextWrapping = Avalonia.Media.TextWrapping.Wrap,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Left
};
// 设置背景颜色
if (!string.IsNullOrEmpty(shape.FillColor))
{
textBlock.Background = new SolidColorBrush(Color.Parse(shape.FillColor));
}
return textBlock;
}
else if (!string.IsNullOrEmpty(shape.ImagePath))
{
// 创建图片控件
var image = new Image
{
Stretch = Stretch.Uniform
};
// 这里需要加载图片,暂时返回空
return null;
}
else
{
// 创建矩形
var rectangle = new Border
{
CornerRadius = new CornerRadius(0)
};
// 设置填充颜色
if (!string.IsNullOrEmpty(shape.FillColor))
{
rectangle.Background = new SolidColorBrush(Color.Parse(shape.FillColor));
}
// 设置边框
if (!string.IsNullOrEmpty(shape.BorderColor))
{
rectangle.BorderBrush = new SolidColorBrush(Color.Parse(shape.BorderColor));
rectangle.BorderThickness = new Thickness(shape.BorderWidth);
}
return rectangle;
}
}
}
}