【发布时间】:2014-04-16 12:50:24
【问题描述】:
我正在尝试制作一个随时间减少的条形图。
使用的xaml是
<Grid x:Name="LayoutRoot" Background="Transparent">
<TextBlock Text="Timer :-" FontSize="35" Width="120" Height="70" Margin="138,167,222,531" ></TextBlock>
<TextBlock x:Name="clock" FontSize="35" Width="100" Height="70" Margin="259,169,121,529" ></TextBlock>
<Image x:Name="bar" Width="350" Height="20" Source="Assets/progress_bar_bg.png" Margin="65,271,65,477" ></Image>
<Image x:Name="gbar" Width="350" Height="20" Source="Assets/green_progress_bar.png" Margin="65,271,65,477" ></Image>
</Grid>
我的 c# 代码是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using System.Windows.Threading;
using Microsoft.Phone.Shell;
namespace PhoneApp1
{
public partial class ProgressBar : PhoneApplicationPage
{
public ProgressBar()
{
InitializeComponent();
newTimer.Interval = TimeSpan.FromSeconds(1);
newTimer.Tick += OnTimerTick;
newTimer.Start();
clock.Text = " 00:60";
}
DispatcherTimer newTimer = new DispatcherTimer();
int counter = 60;
int width = 350;
double i=5.8;
void OnTimerTick(Object sender, EventArgs args)
{
counter--;
if (counter < 0)
{
newTimer.Stop();
counter = 60;
}
else
{
gbar.Width = width - i;
clock.Text = " 00:" + counter.ToString();
i=i+5.8;
}
}
}
}
我已经减小了宽度,使得图像 green_progress_bar.png 的大小应该减小,但问题是它从两端减小,我希望它应该从右到左减小,因为时间从 60 秒减少到 0秒。而且高度也随着时间的推移而降低,我希望图像高度被固定。
这是我的情况的图像。
我希望栏的宽度应该从右到左减小。但它从两端减小。 请帮帮我。
提前致谢。
【问题讨论】:
-
还请注意,当您的时间低于 10 秒时,它实际上会显示
00:9而不是00:09... -
必须使用图片吗?修改一个Slider的样式不是更简单吗?
-
@mehow 我已经纠正了你指出的问题,当时间低于 10 秒时,它实际上显示 00:9 而不是 00:09
-
@Romasz 图片不是强制性的,但我对 Slider 了解不多,所以如果你能帮助我,我会很高兴的。
标签: c# wpf xaml windows-phone-8