Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 日历日颜色取决于列表_C#_Wpf_Xaml_Binding_Calendar - Fatal编程技术网

C# 日历日颜色取决于列表

C# 日历日颜色取决于列表,c#,wpf,xaml,binding,calendar,C#,Wpf,Xaml,Binding,Calendar,我正在考虑一个日历,它连接到包含两个属性的简单对象列表:DateTime和string(包含十六进制颜色) 是否可以从代码级别通过日期按钮进行迭代,或者在xaml中使用某种数据模板来检查列表是否包含指定的日期并将其颜色返回到边框 我唯一发现的是Telerik解决方案,但它需要它们的控制库才能工作,我想知道是否还有其他选项。使用“日到色”多值转换器将“当前日”按钮和“我的彩色日”集合作为值传递 public object Convert(object[] values, Type targetTy

我正在考虑一个日历,它连接到包含两个属性的简单对象列表:DateTime和string(包含十六进制颜色)

是否可以从代码级别通过日期按钮进行迭代,或者在xaml中使用某种数据模板来检查列表是否包含指定的日期并将其颜色返回到边框


我唯一发现的是Telerik解决方案,但它需要它们的控制库才能工作,我想知道是否还有其他选项。

使用“日到色”多值转换器将“当前日”按钮和“我的彩色日”集合作为值传递

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        var result = "Transparent";

        if (!(values[0] is DateTime))
            return result;

        ObservableCollection<Log> collection = null;

        if (values[1] is ObservableCollection<Log>)
            collection = (ObservableCollection<Log>) values[1];

        if (collection != null)
        {
            foreach (var log in collection.Where(log => (DateTime) values[0] == log.Date.Date))
            {
                result = log.BackgroundColor;
                break;
            }
        }

        return new SolidColorBrush((Color) ColorConverter.ConvertFromString(result));
    }

<Style TargetType="{x:Type Border}">
<Setter Property="BorderBrush">
    <Setter.Value>
        <MultiBinding Converter="{StaticResource DayColorConv}" FallbackValue="Transparent">
            <Binding/>
            <Binding Path="CurrentLogs" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type panels:Schedule}}"/>
        </MultiBinding>
    </Setter.Value>
</Setter>
公共对象转换(对象[]值,类型targetType,对象参数,CultureInfo区域性) { var result=“透明”; 如果(!(值[0]是日期时间)) 返回结果; ObservableCollection集合=null; if(值[1]是可观察的集合) 集合=(ObservableCollection)值[1]; if(集合!=null) { foreach(集合中的var log.Where(log=>(DateTime)值[0]==log.Date.Date)) { 结果=log.BackgroundColor; 打破 } } 返回新的SolidColorBrush((颜色)ColorConverter.ConvertFromString(结果)); }