【问题标题】:how to fill the color for rectangle by given value in window phone 7如何在window phone 7中用给定值填充矩形的颜色
【发布时间】:2014-03-12 09:22:06
【问题描述】:

我们可以用给定的值填充矩形吗?

   <Rectangle Width="250" Height="50" Fill="White" Stroke="Black" StrokeThickness="4" RadiusX="20" RadiusY="20" />

如果我给 50 表示矩形应该填充 50% 黄色。(剩余的 50% 应该是白色)。 如果我给 20 表示矩形应该填充 20% 黄色。(剩余的 80% 应该是白色)。 在 windows phone 7 中可以吗?

请让我知道这方面的任何想法。请。

我尝试给出 ViewModel 的值。但我不知道如何为矩形赋予 50%、20%、75% 的颜色。

【问题讨论】:

  • nopes.... 在单个矩形控件中是不可能的.. 此外,您可以通过动态制作 2 个矩形来模仿您的要求

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


【解决方案1】:

您应该使用具有 2 行(或单元格,取决于您想要的方向)的 Grid 控件。网格允许您使用成比例的高度和宽度。

行 Height 属性绑定到您的 ViewModel。

然后在第一个网格行中放置一个具有所需颜色的矩形。

示例代码:

<Grid Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="{Binding Height1}"/>
        <RowDefinition Height="{Binding Height2}"/>
    </Grid.RowDefinitions>
    <Rectangle Fill="Yellow" />
</Grid>

【讨论】:

  • 嗨奥利维尔佩恩..!!谢谢你的提示..!!现在我有了一个想法!!
猜你喜欢
  • 2011-03-11
  • 1970-01-01
  • 2012-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-27
相关资源
最近更新 更多