DatePicker 的 IsSynchronizedWithCurrentItem (或等效项)?

发布于 2024-08-15 07:33:41 字数 605 浏览 1 评论 0原文

我目前有一个绑定到 ObservableCollection 的组合框

    <ComboBox ItemsSource="{Binding Past}" DisplayMemberPath="Date" IsSynchronizedWithCurrentItem="True"/>

,使用“IsSynchronizedWithCurrentItem”,它与一组标签“同步”,这些标签在一组标签中显示下面的数据,例如:

    <Label DataContext="{Binding SelectedDate}" Content="{Binding Minimum}" />

因为使用 DatePicker 选择日期要容易得多(就像 WPF 工具包那样,http://wpf.codeplex.com/)而不是带有超过其中有 300 个日期,是否有办法设置“IsSynchronizedWithCurrentItem”之类的内容,以便 DatePicker 可以控制“当前日期”?

谢谢

I currently have a combobox with bound to an ObservableCollection

    <ComboBox ItemsSource="{Binding Past}" DisplayMemberPath="Date" IsSynchronizedWithCurrentItem="True"/>

Using, 'IsSynchronizedWithCurrentItem' it "synchronizes" with a set of labels that show the data below in a set of labels like:

    <Label DataContext="{Binding SelectedDate}" Content="{Binding Minimum}" />

As it is a lot easier to select a date using a DatePicker (like the WPF Toolkit one, http://wpf.codeplex.com/) rather than a combobox with over 300 dates in it, is there someway to set something like 'IsSynchronizedWithCurrentItem' so that the DatePicker can control the 'current date'?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-08-22 07:33:41

我通过在视图模型中创建“CurrentDate”属性解决了这个问题:

    public DateTime CurrentDate
    {
        get { return (this.collectionView.CurrentItem as PastItem).Date; }
        set 
        { 
            this.collectionView.MoveCurrentTo(Past.Where(PastItem => PastItem.Date == Convert.ToDateTime(value)).FirstOrDefault()); 
        }
    }

然后为第一个和第二个属性创建两个属性。最后一个日期:

    public DateTime FirstDate
    {
        get { return this.Past.FirstOrDefault().Date; }
    }
    public DateTime LastDate
    {
        get { return this.Past.LastOrDefault().Date; }
    }

然后使用 DatePicker 绑定到这些属性:

    <wpf:DatePicker SelectedDate="{Binding CurrentDate}" DisplayDateStart="{Binding FirstDate, Mode=OneWay}" DisplayDateEnd="{Binding LastDate, Mode=OneWay}" />

这意味着 DatePicker 将仅限于第一个和最后一个日期:最后日期,并且可以选择一个日期,链接到详细信息。

I solved this by creating a 'CurrentDate' Property in my View Model:

    public DateTime CurrentDate
    {
        get { return (this.collectionView.CurrentItem as PastItem).Date; }
        set 
        { 
            this.collectionView.MoveCurrentTo(Past.Where(PastItem => PastItem.Date == Convert.ToDateTime(value)).FirstOrDefault()); 
        }
    }

and then creating two property's for the first & the last dates:

    public DateTime FirstDate
    {
        get { return this.Past.FirstOrDefault().Date; }
    }
    public DateTime LastDate
    {
        get { return this.Past.LastOrDefault().Date; }
    }

and then binding to these properties using the DatePicker:

    <wpf:DatePicker SelectedDate="{Binding CurrentDate}" DisplayDateStart="{Binding FirstDate, Mode=OneWay}" DisplayDateEnd="{Binding LastDate, Mode=OneWay}" />

This meant that the DatePicker would be limited to the first & the last dates, and one can choose a date, linked to the details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文