RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 845203
Accepted
Gloom_V01
Gloom_V01
Asked:2020-06-22 13:24:41 +0000 UTC2020-06-22 13:24:41 +0000 UTC 2020-06-22 13:24:41 +0000 UTC

Wpf 日历更改 CalendarItem

  • 772

问题是是否可以创建/更改 CalendarItem 的样式,以便您还可以显示 BlackoutDates 模型中的附加值(粗略地说是一个数字)?

我只想在从模型中获取 16 和 BlackoutDates 的情况下得到这样的东西。上图日期根据“选择”范围而变化,不幸的是我无法为屏幕执行此操作。这意味着第一组 BlackoutDates (1-14) 包含数字 16,第二组 (15) 17,第三组 (23-28) 18。这就是你想要的那种逻辑。可能吗?

在此处输入图像描述

据我了解 Calendar.BlackoutDates 可以通过 Attached.property 绑定

我将建议的更改添加到 CalendarDayButtonStyle 样式。我抛弃了所有我不需要的动作(我希望)。

<Style x:Key="CalendarDayButtonStyle1" TargetType="{x:Type CalendarDayButton}">
    <Setter Property="MinWidth" Value="5"/>
    <Setter Property="MinHeight" Value="5"/>
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="Height" Value="25"/>
    <Setter Property="Width" Value="25"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type CalendarDayButton}">
                <Grid >
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="BlackoutDayStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="NormalDay"/>
                            <VisualState x:Name="BlackoutDay">
                                <Storyboard>
                                    <!--<DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Blackout"/>-->
                                    <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TodayBackground"/>
                                    <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="UpName"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Rectangle x:Name="TodayBackground" Fill="#FFAAAAAA" Opacity="0" RadiusY="1" RadiusX="1"/>
                    <Border BorderThickness="1" BorderBrush="DarkGray"/>
                    <Rectangle x:Name="SelectedBackground" Fill="#FFBADDE9" Opacity="0" RadiusY="1" RadiusX="1"/>
                    <ContentPresenter x:Name="NormalText" 
                                      TextElement.Foreground="#FF333333" 
                                      Margin="5,1,2,1"
                                      TextElement.FontSize="11"

                                      HorizontalAlignment="Right"
                                      VerticalAlignment="Bottom"
                                      />
                    <Label x:Name="UpName" Content="16" FontSize="9" Padding="0" Opacity="0" BorderThickness="1" BorderBrush="LightGray" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

计划绑定到元素UpName

c#
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Gloom_V01
    2020-07-02T19:10:53Z2020-07-02T19:10:53Z

    总的来说,我完成了这个项目,其中包含一个不可点击的月份范围显示和附加信息。只能通过多重绑定和转换器来连接日历元素。一般来说是这样的。

    XAML

    <UserControl x:Class="YearClendar.MonthCalendar.MonthCalendar"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:YearClendar.MonthCalendar"
                 xmlns:Convert="clr-namespace:MonthCalendar.Converters"
                 xmlns:helpers="clr-namespace:MonthCalendar.Helpers"             
                 mc:Ignorable="d" 
                 d:DesignHeight="300" d:DesignWidth="300" >
        <UserControl.Resources>
            <Convert:NumberDateConverter x:Key="NumberDateConverter"/>
            <Convert:NeedShowBack x:Key="NeedShowBack"/>
            <Convert:BackgroundItemConverter x:Key="BackgroundItemConverter"/>
            <Convert:NumForeItemConverter x:Key="NumForeItemConverter"/>     
            <Style x:Key="CalendarStyle_2" TargetType="{x:Type Calendar}">
                <Setter Property="Foreground" Value="#FF333333"/>
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFE4EAF0" Offset="0"   />
                            <GradientStop Color="#FFECF0F4" Offset="0.16"/>
                            <GradientStop Color="#FFFCFCFD" Offset="0.16"/>
                            <GradientStop Color="#FFFFFFFF" Offset="1"   />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderBrush">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFA3AEB9" Offset="0"/>
                            <GradientStop Color="#FF8399A9" Offset="0.375"/>
                            <GradientStop Color="#FF718597" Offset="0.375"/>
                            <GradientStop Color="#FF617584" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Calendar}">
                            <StackPanel x:Name="PART_Root" HorizontalAlignment="Center">
                                <CalendarItem x:Name="PART_CalendarItem" 
                                              BorderBrush="{TemplateBinding BorderBrush}" 
                                              BorderThickness="{TemplateBinding BorderThickness}" 
                                              Background="{TemplateBinding Background}" 
                                              Style="{TemplateBinding CalendarItemStyle}"/>
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
            <Style x:Key="CalendarButtonStyle_2" TargetType="{x:Type CalendarButton}">
                <Setter Property="Background" Value="#FFBADDE9"/>
                <Setter Property="MinWidth" Value="40"/>
                <Setter Property="MinHeight" Value="42"/>
                <Setter Property="FontSize" Value="10"/>
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type CalendarButton}">
                            <Grid>                          
                                <ContentPresenter x:Name="NormalText" TextElement.Foreground="#FF000000" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1,0,1,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>                            
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
            <Style x:Key="CalendarItemStyle_2" TargetType="{x:Type CalendarItem}">
                <Setter Property="Margin" Value="0,1,0,1"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type CalendarItem}">
                            <ControlTemplate.Resources>
                                <DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
                                    <TextBlock Foreground="#FF000000" FontWeight="Bold" FontSize="9.5" 
                                               FontFamily="Verdana" HorizontalAlignment="Center" Margin="0,2,0,2" 
                                               Text="{Binding}" VerticalAlignment="Center"/>
                                </DataTemplate>
                            </ControlTemplate.Resources>
                            <Grid x:Name="PART_Root">
                                <Grid.Resources>
                                    <SolidColorBrush x:Key="DisabledColor" Color="#A5FFFFFF"/>
                                </Grid.Resources>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual"/>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="1">
                                    <Border BorderBrush="#FFFFFFFF" BorderThickness="2" CornerRadius="1">
                                        <Grid>
                                            <Grid.Resources>
                                            </Grid.Resources>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto"/>
                                                <RowDefinition Height="*"/>
                                            </Grid.RowDefinitions>
                                            <TextBlock 
                                                       Grid.Column="1" 
                                                       FontWeight="Bold"
                                                       Focusable="False" 
                                                       FontSize="10.5" 
                                                 Foreground="Black"
                                                       HorizontalAlignment="Stretch" 
                                                       TextAlignment="Center" 
                                                       Grid.Row="0" 
                                                       VerticalAlignment="Stretch"
                                                Text="{Binding ElementName=PART_HeaderButton,Path=Content}" Margin="0" Width="Auto"
                                                />
                                            <Button x:Name="PART_HeaderButton" Grid.Column="1" FontWeight="Bold" Visibility="Collapsed" FontSize="10.5" HorizontalAlignment="Center" Grid.Row="0"   VerticalAlignment="Center"/>
    
                                            <Grid x:Name="PART_MonthView" Grid.ColumnSpan="3" HorizontalAlignment="Center" Margin="1,-1,1,1" Grid.Row="1" Visibility="Visible">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>
                                            </Grid>
    
                                        </Grid>
                                    </Border>
                                </Border>
                                <Rectangle x:Name="PART_DisabledVisual" Fill="{StaticResource DisabledColor}" Opacity="0" RadiusY="2" RadiusX="2" Stretch="Fill" Stroke="{StaticResource DisabledColor}" StrokeThickness="1" Visibility="Collapsed"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Visibility" TargetName="PART_DisabledVisual" Value="Visible"/>
                                </Trigger>
                                <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Year">
                                    <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden"/>
    
                                </DataTrigger>
                                <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Decade">
                                    <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden"/>
                                </DataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <ControlTemplate x:Key="ButtonControlTemplate_2" TargetType="{x:Type Button}">
                <ContentPresenter x:Name="buttonContent" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" TextElement.Foreground="#FF333333" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
    
                </ContentPresenter>
            </ControlTemplate>
    
            <Style x:Key="CalendarDayButtonStyle_2" TargetType="{x:Type CalendarDayButton}">
    
                <Setter Property="MinWidth" Value="5"/>
                <Setter Property="MinHeight" Value="5"/>
                <Setter Property="FontSize" Value="16"/>
                <Setter Property="Height" Value="25"/>
                <Setter Property="Width" Value="25"/>
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type CalendarDayButton}">
                            <Grid >
                                <Grid.Resources>
                                    <helpers:BindingProxy x:Key="proxy" Data="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MonthCalendar}}, Path=DataContext}" />
                                </Grid.Resources>
                                <Border BorderThickness="1" BorderBrush="DarkGray"/>
    
                                <Rectangle x:Name="AccentBackground" RadiusX="1" RadiusY="1" Opacity="0.3" IsHitTestVisible="False">
                                    <Rectangle.Fill>
                                        <MultiBinding  Converter="{StaticResource BackgroundItemConverter}">
                                            <MultiBinding.Bindings>
                                                <Binding />
                                                <Binding Source="{StaticResource proxy}" Path="Data.SelectedDays"/>
                                            </MultiBinding.Bindings>
                                        </MultiBinding>
                                    </Rectangle.Fill>
                                    <Rectangle.Visibility>
                                        <MultiBinding Converter="{StaticResource NeedShowBack}">
                                            <MultiBinding.Bindings>
                                                <Binding />
                                                <Binding Source="{StaticResource proxy}" Path="Data.SelectedDays"/>                                                                                        
                                            </MultiBinding.Bindings>
                                        </MultiBinding>
                                    </Rectangle.Visibility>
                                </Rectangle>
    
    
                                <Label x:Name="NormalText" TextElement.Foreground="#FF000000" 
                                                           Padding="0" 
                                                           Margin="5,1,2,1" 
                                                           TextElement.FontSize="11"
                                                  Content="{Binding Day}"
                                                  HorizontalAlignment="Right"
                                                  VerticalAlignment="Bottom"/>
    
    
    
                                <Label x:Name="UpName" FontSize="9" 
                                       Padding="2,0,0,0"     
                                       BorderThickness="1"
    
                                       VerticalAlignment="Top"
                                       HorizontalAlignment="Left">
                                    <Label.Foreground>
                                        <MultiBinding Converter="{StaticResource NumForeItemConverter}">
                                            <MultiBinding.Bindings>
                                                <Binding />
                                                <Binding  Source="{StaticResource proxy}" Path="Data.SelectedDays"/>                                          
                                            </MultiBinding.Bindings>
                                        </MultiBinding>
                                    </Label.Foreground>
                                    <MultiBinding Converter="{StaticResource NumberDateConverter}">
                                        <MultiBinding.Bindings>
                                            <Binding />
                                            <Binding  Source="{StaticResource proxy}" Path="Data.SelectedDays"/>
                                        </MultiBinding.Bindings>
                                    </MultiBinding>
                                    <Label.Style>
                                        <Style TargetType="{x:Type Label}">
                                            <Setter Property="BorderBrush" Value="Gray"/>
                                            <Style.Triggers>
                                                <Trigger Property="Content" Value="{x:Null}">
                                                    <Setter Property="BorderBrush" Value="Transparent"/>
                                                </Trigger>
                                            </Style.Triggers>
                                                </Style>
                                    </Label.Style>
                                </Label>
                            </Grid>
    
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </UserControl.Resources>
        <Grid>
    

    类模型

    namespace MonthCalendar.Model
    {
       public class MonthModel : BaseModel
        {
            private DateTime p_DisplayDate;
             private DateTime m_OldDisplayDate;
            Dictionary<DateTime, SelectDayElemet> _SelectedDays;
           public Dictionary<DateTime, SelectDayElemet> SelectedDays
            {
                get { return _SelectedDays; }
                set {
                      _SelectedDays =value;
                      OnPropertyChanged(()=>SelectedDays);
                    }
            }
            public void Update()
            {
                OnPropertyChanged(() => SelectedDays);
                  OnPropertyChanged(() => DisplayDate);
                OnPropertyChanged(() => DisplayDateStart);
                OnPropertyChanged(() => DisplayDateEnd);
            }
    
            public MonthModel()
            {
                this.Initialize();
            }
            public event EventHandler RefreshRequested;
            private void RequestRefresh()
            {
                RefreshRequested?.Invoke(this, new EventArgs());
            }
    
    
            public DateTime DisplayDate
            {
                get { return GetFirstDay(); }
                set
                {
                    WorkMonth = value;
                    GetFirstDay();
                    OnPropertyChanged(() => DisplayDate);
                }
            }
            DateTime GetFirstDay()
            {
                DateTime tmp1 = new DateTime(WorkMonth.Year, WorkMonth.Month, 1);
                return new DateTime(WorkMonth.Year, WorkMonth.Month, 1);
            }
    
            DateTime GetLastDay()
            {
                if (WorkMonth.Month==12)
                    return new DateTime(WorkMonth.Year, WorkMonth.Month, 31);
                DateTime tmp2 = new DateTime(WorkMonth.Year, WorkMonth.Month + 1, 1);
                DateTime tmp3 = tmp2.AddDays(-1);
    
                return new DateTime(tmp3.Year, tmp3.Month, tmp3.Day);
            }
            private void Initialize()
            {
    
                WorkMonth = DateTime.Today;
                SelectedDays = new Dictionary<DateTime, SelectDayElemet>();
                this.PropertyChanged += OnPropertyChanged;
            }
    
            public DateTime DisplayDateStart
            {
                get { return GetFirstDay(); }
                set { }
            }
            public DateTime DisplayDateEnd
            {
                get { return GetLastDay(); }
                set { }
            }
            DateTime _p_DisplayDate;
            public DateTime WorkMonth
            {
                get { return _p_DisplayDate; }
                set
                {
                    _p_DisplayDate = value;
                    OnPropertyChanged(() => p_DisplayDate);
                    OnPropertyChanged(() => DisplayDate);
                    OnPropertyChanged(() => DisplayDateStart);
                    OnPropertyChanged(() => DisplayDateEnd);
                }
            }    
            private void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                // Ignore properties other than DisplayDate
                if (e.PropertyName != "DisplayDate") return;
    
                // Ignore change if date is DateTime.MinValue
                if (DisplayDate == DateTime.MinValue) return;
    
                // Ignore change if month is the same
                if (DisplayDate.IsSameMonthAs(m_OldDisplayDate)) return;
    
    
                // Update OldDisplayDate
                m_OldDisplayDate = p_DisplayDate;
            }
            #region Administrative Properties
            public virtual bool IgnorePropertyChangeEvents { get; set; }    
            #endregion
        }
    }
    

    元素类继承自实现接口的 BaseModel

    INotifyPropertyChanged,INotifyPropertyChanged

    public class SelectDayElemet: BaseModel
     {
        public SelectDayElemet()
         {
             //Date = new DateTime();
             Background = new LinearGradientBrush(
                 new GradientStopCollection()
                     {
                      new GradientStop((Color)ColorConverter.ConvertFromString("#FFE4EAF0"),0),
                      new GradientStop((Color)ColorConverter.ConvertFromString("#FFECF0F4"),0.16),
                      new GradientStop((Color)ColorConverter.ConvertFromString("#FFFCFCFD"),0.16),
                      new GradientStop((Color)ColorConverter.ConvertFromString("#FFFFFFFF"),1),
                     });
    
             NumForeground = new SolidColorBrush(Colors.Black);
             //  DayForeground = new SolidColorBrush(Colors.Black);
         }
       //  , Brush __DayForeground
         public SelectDayElemet(int __num, Brush __Background, Brush __NumForeground)
         {
             _NUM          = __num;
             Background    = __Background;
             NumForeground = __NumForeground;
             //   DayForeground = __DayForeground;
         }
         //, string __StrDayForeground
         public SelectDayElemet(int __num, string __StrBackground, string __StrForeground)
         {
             _NUM = __num;
             Background    = new SolidColorBrush((Color)ColorConverter.ConvertFromString(__StrBackground));
             NumForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(__StrForeground));
            // DayForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(__StrDayForeground));
         }
    
         int _NUM;
        public int NUM
         {
             get { return _NUM; }
             set {
                   _NUM = value;
                   OnPropertyChanged(()=>NUM);
                 }
         }
    
         Brush _Background;
        public Brush Background
         {
             get { return _Background; }
             set {
                   _Background = value;
                   OnPropertyChanged(()=>Background);
                 }
         }
    
         Brush _NumForeground;
        public Brush NumForeground
         {
             get { return _NumForeground; }
             set {
                   _NumForeground = value;
                   OnPropertyChanged(()=>NumForeground);
                 }
         }
    

    BindingProxy 是个很酷的东西

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    
    namespace MonthCalendar.Helpers
    {
        /**
         * @brief Прокси класс для доступа к данным 
         * взято с https://social.technet.microsoft.com/wiki/contents/articles/31422.wpf-passing-a-data-bound-value-to-a-validation-rule.aspx
         * 
         */
        public class BindingProxy : System.Windows.Freezable
        {
            /**
             * @brief Согласно требованиям "необходимо переопределить подкласс CreateInstanceCore метод" переопределяем
             */
            protected override Freezable CreateInstanceCore()
            {
                return new BindingProxy();
            }
            /**
             * @brief объект данных который будем "биндить"
             */
            public object Data
            {
                get { return (object)GetValue(DataProperty); }
                set { SetValue(DataProperty, value); }
            }
    
            /**
             * @brief Создаем DependencyProperty с именем "Data"
             */
            public static readonly DependencyProperty DataProperty =
                DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new PropertyMetadata(null));
        }
    }
    

    约定,我想不出比多重绑定更好的方法

    using MonthCalendar.Helpers;
    using MonthCalendar.Model;
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Data;
    
    namespace MonthCalendar.Converters
    {
        public class NumberDateConverter : IMultiValueConverter
        {
            public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
            {
                try
                {
                    if ((values[0] == null) || (values[1] == null)) return DependencyProperty.UnsetValue;
                    if ((values[0] == DependencyProperty.UnsetValue) || (values[1] == DependencyProperty.UnsetValue)) return DependencyProperty.UnsetValue;
                    var targetDate = (DateTime)values[0];
                    var SelectedDays = (Dictionary<DateTime, SelectDayElemet>)values[1];
    
                    try
                    {
                      SelectDayElemet val = null;
                      var res = SelectedDays.TryGetValue(targetDate, out val);
                      if (res)
                      return val.NUM.ToString();//parent.SelectedDays[targetDate].ToString();
                      else
                            return DependencyProperty.UnsetValue;
                    }
                    catch (Exception ex)
                    {
                        return DependencyProperty.UnsetValue;
                    }
                }
                catch (Exception ex)
                {
                    return DependencyProperty.UnsetValue;
                }
            }
    
            public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }   
    }
    
    • 2

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5