在WPF中,我需要指定日歷中的某一天改變背景顏色,需要怎樣操作?例如,2021年4月1日。然后當日的背景顏色發生改變,或者是在這個日期上添加圖示
uj5u.com熱心網友回復:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<local:Ticker x:Key="ticker"></local:Ticker>
</Window.Resources>
<Grid>
<Calendar HorizontalAlignment="Left" Margin="382,142,0,0" VerticalAlignment="Top">
<Calendar.Style>
<Style TargetType="Calendar">
<Style.Triggers>
<DataTrigger Binding="{Binding Source={StaticResource ticker},Path=Now,Mode=OneWay}" Value="https://bbs.csdn.net/topics/2021-04-09">
<Setter Property="Background" Value="https://bbs.csdn.net/topics/Red"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Calendar.Style>
</Calendar>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApp1
{
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public class Ticker : INotifyPropertyChanged
{
public Ticker()
{
Timer timer = new Timer();
timer.Interval = 1000; // 1 second updates
timer.Elapsed += timer_Elapsed;
timer.Start();
}
public string Now
{
get
{
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd"));
return DateTime.Now.ToString("yyyy-MM-dd");
}
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Now"));
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
uj5u.com熱心網友回復:
我覺得你誤會我意思了。例如我設定了2021年3月10日到資料庫里面。然后,一打開日歷,3月10日的單個單元格的背景顏色改變。而不是整個日歷改變
uj5u.com熱心網友回復:
https://docs.microsoft.com/zh-cn/archive/msdn-magazine/2009/june/customizing-the-new-wpf-calendar-controlsuj5u.com熱心網友回復:
進入不了
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/274308.html
標籤:C#
上一篇:集體漲薪,沒有我
下一篇:各位大佬,求教一個C#問題
