【发布时间】:2011-08-08 01:41:15
【问题描述】:
好的,所以我想显示一些属性,但前提是它们的开始时间是今天的日期。
有没有办法使用通配符来表示值?还是在 Where 子句中列出多个值?
这是一个例子..我在想是否可以拉出当前时间然后转换为字符串( var time = DateTime.Now.ToString("yyyyMMddHHmmss");) 我可以使用该 var 作为过滤器属性。这里 ... where tv.Attribute("start").Value == time
编辑**
我已经更新了代码,使其更清楚我所追求的。正如您在下面看到的,我使用 Where 子句来显示与特定“开始”时间相关的属性。
现在这个例子对我不起作用,因为首先它需要是 24 小时内的所有列表,而不是下面的特定时间,还因为我想按 DateTime.Now 动态显示列表。
所以,我真正需要的是一种显示当前日期的方法,但不是将特定时间显示为布尔值,并在我的布尔方程中使用它来显示当前日期的“开始”属性。
WebClient c = new WebClient();
c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(c_DownloadStringCompleted);
c.DownloadStringAsync(new Uri("http://www.domain.com/source.xml"));
progressBar1.IsIndeterminate = true;
progressBar1.Visibility = Visibility.Visible;
}
void c_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
var r = XDocument.Parse(e.Result);
listBox2.ItemsSource = from tv in r.Root.Descendants("programme")
where tv.Attribute("start").Value == "20110724190000 +1200"
let channelE1 = tv.Attribute("channel")
let startE1 = tv.Attribute("start")
let nameEl = tv.Element("title")
orderby tv.Attribute("start").Value ascending
let urlEl = tv.Element("desc")
select new TV1guide
{
DisplayName = nameEl == null ? null : nameEl.Value,
ChannelName = channelE1 == null ? null : channelE1.Value,
ChannelURL = urlEl == null ? null : urlEl.Value,
StartTime = startE1 == null ? (DateTime?)null : DateTime.ParseExact(startE1.Value, "yyyyMMddHHmmss zzz", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeLocal),
};
progressBar1.IsIndeterminate = false;
progressBar1.Visibility = Visibility.Collapsed;
public class TV1guide
{
public string DisplayName { get; set; }
public string ChannelURL { get; set; }
public string ImageSource { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public string ChannelName { get; set; }
}
}
}
除此之外,我还尝试了 HiTech Magic 的建议,但我很确定语法是错误的。
WebClient c = new WebClient();
c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(c_DownloadStringCompleted);
c.DownloadStringAsync(new Uri("http://www.domain.com/source.xml"));
progressBar1.IsIndeterminate = true;
progressBar1.Visibility = Visibility.Visible;
}
bool MyDateCheckingMethod( DateTime otherDate )
{
// Is this today (ignoring time)?
return otherDate.Date == DateTime.Now.Date;
}
void c_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
var r = XDocument.Parse(e.Result);
listBox2.ItemsSource = from tv in r.Root.Descendants("programme")
where MyDateCheckingMethod(tv.Attribute("start").Value)
let channelE1 = tv.Attribute("channel")
let startE1 = tv.Attribute("start")
let nameEl = tv.Element("title")
orderby tv.Attribute("start").Value ascending
let urlEl = tv.Element("desc")
select new TV1guide
{
DisplayName = nameEl == null ? null : nameEl.Value,
ChannelName = channelE1 == null ? null : channelE1.Value,
ChannelURL = urlEl == null ? null : urlEl.Value,
StartTime = startE1 == null ? (DateTime?)null : DateTime.ParseExact(startE1.Value, "yyyyMMddHHmmss zzz", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeLocal),
};
progressBar1.IsIndeterminate = false;
progressBar1.Visibility = Visibility.Collapsed;
public class TV1guide
{
public string DisplayName { get; set; }
public string ChannelURL { get; set; }
public string ImageSource { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public string ChannelName { get; set; }
}
}
}
【问题讨论】:
标签: silverlight windows-phone-7 linq-to-xml where