【发布时间】:2014-10-14 18:21:37
【问题描述】:
我在我的应用程序中添加了ProgressBar,我希望它具有透明背景,所以我这样做了:
<ProgressBar IsIndeterminate="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ProgressBar.Background>
<SolidColorBrush Color="Black" Opacity="0.5" />
</ProgressBar.Background>
</ProgressBar>
在预览窗口中一切看起来都很好,但是,当我运行我的应用程序时,Background 根本不存在。我找到的解决方案是将ProgressBar 放在网格中并在Grid 中设置Background 属性,但是由于预览显示正确,并且属性在那里,它不应该工作吗?
更新:
根据@Chris W. 的建议,我尝试覆盖ProgressBar 元素的默认样式,如下所示:
<ProgressBar IsIndeterminate="True" Background="#FF000000" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="50">
<ProgressBar.Style>
<Style TargetType="ProgressBar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Indeterminate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetName="DeterminateRoot"
Storyboard.TargetProperty="Opacity"
To="0.5"
Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ProgressBar.Style>
</ProgressBar>
但仍然没有果汁。
【问题讨论】:
-
ProgressBar 可能有某种样式(可能是 VisualState),它会更改背景而不会在设计器中正确显示。您可以尝试编辑样式或从 MSDN 获取默认样式。
标签: xaml windows-store-apps progress-bar windows-8.1 windows-phone-8.1