我想以以下行为在我的堆栈面板上显示画笔:
- 画笔是 240x120 的图像
- 面板为 240x60
我想显示画笔的一部分,例如 rect(0, 30, 240, 60) (以便面板上的图像向下移动一点)尝试使用视口和 Viewbox 没有结果(空面板)
这是我的代码:
for (int i = 0; i < listExplorationData.Count; i++)
{
StackPanel panelLoop = new StackPanel();
panelLoop.Name = "panel_" + i.ToString();
panelLoop.Width = 240;
panelLoop.Height = 60;
panelLoop.Margin = new Thickness(0, 60 * i, 0, 0);
BitmapImage image = new BitmapImage(
new Uri("pack://application:,,,/GW2-MyWorldExploration;component/Images/" +
listExplorationData[i].mapname_en.Replace(" ", "_") +
"_loading_screen.jpg"));
ImageBrush brush = new ImageBrush();
brush.ImageSource = image;
brush.Stretch = Stretch.None;
brush.Viewport = new Rect(0, 30, 240, 60);
panelLoop.Background = brush;
mainStackPanel.Children.Add(panelLoop);
}