【问题标题】:How to Set Background Color of Viewport如何设置视口的背景颜色
【发布时间】:2014-02-08 05:50:18
【问题描述】:

我想在我的应用页面 (#2B2B2B) 中为 Viewport 控件的背景使用特定颜色。

<ViewportControl
    x:Name="Viewport"
    Grid.Row="0" Grid.RowSpan="2"
    SizeChanged="Viewport_SizeChanged">
    <Image
        x:Name="Image"
        Stretch="Uniform"
        CacheMode="BitmapCache"
        ManipulationStarted="Viewport_ManipulationStarted"
        ManipulationDelta="Viewport_ManipulationDelta"
        ManipulationCompleted="Viewport_ManipulationCompleted">
    </Image>
</ViewportControl>

ViewportControl 中添加Background="#2B2B2B" 无效。
我的要求是创建包含图像的视口的位图,并且由于图像通常不会覆盖整个视口,因此我希望在图像后面有一个柔和的深色背景。

WriteableBitmap wb = new WriteableBitmap((int)Viewport.ActualWidth, (int)Viewport.ActualHeight);
wb.Render(Viewport, null);
wb.Invalidate();

【问题讨论】:

  • 嗯,根据文档,背景是一个有效的属性,也许尝试将 alpha 通道添加到您的颜色中?喜欢Background="#FF2B2B2B" 或者只是在图片后面放一些你知道可以着色的东西,比如RectangleBackground
  • 好吧,在视口背景中添加 alpha 通道没有任何效果,将图像控件放置在视口内的网格中以及将网格的背景设置为颜色也没有效果。
  • 你认为 alpha 值是 50/50,而我认为 Grid 必须是 工作....除了实际上背景属性应该工作,我还没有找到任何类型的模板。
  • 同意。同时我所做的是更改 LayoutRoot 的背景,并切换一个控件的可见性以达到相同的效果。如果我找到解决方案,我会继续研究并发布。

标签: c# xaml windows-phone-7 windows-phone-8 bitmap


【解决方案1】:

您可以将 Viewport 放在堆栈面板中,并为堆栈面板的背景颜色赋予颜色,如果颜色也覆盖了图像,请使用 Zindex。

【讨论】:

    猜你喜欢
    • 2011-01-11
    • 2021-10-02
    • 1970-01-01
    • 2011-03-19
    • 2010-12-11
    • 1970-01-01
    • 2011-03-28
    • 2013-05-06
    • 2016-03-16
    相关资源
    最近更新 更多