挑战
使用最少量的字符计算特定年份(1900-2100)的希腊东正教复活节日期(http://www.timeanddate.com/holidays/us/orthodox-easter-day).
输入只是"2010"形式的一年.它与你得到它(Input,CommandLineArgs等)无关,但它必须是动态的!
输出应该在表格日-月-年(假设dd/mm/yyyy
或d/m/yyyy
)
限制没有标准函数,如Mathematica EasterSundayGreekOrthodox
或PHP easter_date()
,必须使用自动返回(不适用的格里高利)日期!
例子
2005 returns 1/5/2005
2006 returns 23/4/2006
2007 returns 8/4/2007
2008 returns 27/4/2008
2009 returns 19/4/2009
2010 returns 4/4/2010
2011 returns 24/4/2011
2012 returns 15/4/2012
2013 returns 5/5/2013
2014 returns 20/4/2014
2015 returns 12/4/2015
Run Code Online (Sandbox Code Playgroud)
代码计数包括输入/输出(即完整程序).
编辑: 我的意思是东方复活节日期.
通常在我的代码中,我开始的威胁基本上是这样的:
void WatchForSomething()
{
while(true)
{
if(SomeCondition)
{
//Raise Event to handle Condition
OnSomeCondition();
}
Sleep(100);
}
}
Run Code Online (Sandbox Code Playgroud)
只是为了知道某些条件是否为真(例如,如果一个错误的编码库没有事件,只需要布尔变量,我需要它们的"实时视图").
现在我想知道是否有更好的方法来完成这种工作,就像一个Windows函数挂钩,可以运行我的方法所有x秒.或者我应该为我的应用程序编写一个全局事件,提高所有x秒并让他调用我的方法如下:
//Event from Windows or selfmade
TicEvent += new TicEventHandler(WatchForSomething));
Run Code Online (Sandbox Code Playgroud)
然后这个方法:
void WatchForSomething()
{
if(SomeCondition)
{
//Raise Event to handle Condition
OnSomeCondition();
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我希望这不会因为一个"主观问题"或其他问题而被关闭,我只想知道这类工作的最佳实践是什么.
我有一个WPF数据网格(从标题指示的WPF工具包),我想要一些列之间的差距,甚至没有标题在上面,你可以看到之间的背景.我不知道如何管理这个.
顺便说一句,我的所有列都是TemplateColumns,但我更喜欢一个解决方案,我不需要为每一列设置样式,而且它的标题在一侧有一个gab.也许是类似的东西<DataGridGapColum Width="5" />
,不幸的是,这样的事情并不存在.
我试图在另一个LinearGradientBrush的定义中使用一个LinearGradientBrush.但我不知道天气这甚至会起作用,如果它有效,我需要知道如何.
例如:
<LinearGradientBrush x:Key="ComboBoxFocusBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFDEEB3" Offset="0"/>
<GradientStop Color="#FFFBF2CD" Offset="1"/>
<GradientStop Color="#FFFCE48A" Offset="0.5"/>
<GradientStop Color="#FFFBE388" Offset="0.75"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="FilterPopupTitleBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#B45988" Offset="0.75"/>
//Code here to use ComboBoxFocusBackgroundBrush
<GradientStop Color="#990088" Offset="0.75"/>
</LinearGradientBrush>
Run Code Online (Sandbox Code Playgroud)
感谢你期待你的答案
编辑:为了让事情更清楚一点,我想在"FilterPopupTitleBrush"中使用"ComboBoxFocusBackgroundBrush"作为"模板".因此我在两个画笔中都有相同的颜色渐变而没有"<GradientStop"的副本......>" - 标签
我尝试创建一个具有负角半径的边框,如下所示:
我想要内部的半径.这可能是内置函数还是我必须用路径绘制它?
我尝试构建一个DataGrid,并且我想将TextColums的Foreground属性之一绑定到Date,如果Date是过去的话,它将变为红色。
这里是XAML:
<toolkit:DataGridTextColumn
Binding="{Binding Path=Prüfdatum, Converter={StaticResource TimestampToDateConverter}}"
Header="Prüfdatum"
Foreground="{Binding Path=Prüfdatum, Converter={StaticResource TimestampToColorConverter},
ConverterParameter=Prüfdatum}" />
Run Code Online (Sandbox Code Playgroud)
这是我的转换器:
class TimestampToColorConverter: IValueConverter
{
#region IValueConverter Member
public object Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
string Datum = value.ToString();
int year = System.Convert.ToInt32(Datum.Substring(6, 4));
int month = System.Convert.ToInt32(Datum.Substring(3, 2));
int day = System.Convert.ToInt32(Datum.Substring(0, 2));
int hour = System.Convert.ToInt32(Datum.Substring(11, 2));
int minute = System.Convert.ToInt32(Datum.Substring(14, 2));
int second = System.Convert.ToInt32(Datum.Substring(17, 2));
DateTime Time = new DateTime(year, month, day, hour, minute, second);
if (Time < …
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个能够从XAML中获取元素的usercontrol,如下所示:
<ComboBox >
<ComboBoxItem />
<ComboBoxItem />
<ComboBoxItem />
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
在ComboBox
,你可以只在ComboBox
标签之间添加Items ,我想复制它,但我不知道从哪里开始.
完了它应该是这样的:
<cis:ReportControl Grid.Row="3">
<cis:ReportItem />
</cis:ReportControl>
Run Code Online (Sandbox Code Playgroud)
在cis:ReportControl
,有一些Button
s和一个ComboBox
,基本上我只想ComboBox
用物品喂.
报告项目只是ComboBoxItem
一些额外的属性.
编辑:
我已根据@Snowbears的答案实现了它,但现在的问题是控件本身就是一个项目.我认为这是因为我有一些内容,通过定义ContentProperty
我的内容ComboBox
,它被重定向到Box.我该怎么做才能避免这种情况?
编辑二:
它完全适用于此:
private ItemCollection reportItems;
public ItemCollection ReportItems
{
get
{
if (reportItems == null)
{
reportItems = this.ComboBoxReports.Items;
}
return reportItems;
}
}
Run Code Online (Sandbox Code Playgroud)
与[ContentProperty("ReportItems")]
属性.ComboBoxReports是Control中的ComboBox,我不得不继承ItemsControl
它以使其工作.
我创建具有一个WPF应用程序Canvas
上,我把UserControls
它们是由用户(就像Windows的窗口)可移动和调整大小.现在我已经发现这对于旧PC而言可能非常慢,这是一个问题.
作为一个解决方案,我考虑生成一个显示UserControl的图形,并在调整Control/draging时显示,以防止WPF永久重新计算所有元素.唯一的问题是我不知道如何生成这个图像.
是否有类似于.Net的功能?或者我怎么能自己做?
我上课了
public class Setting<T>
{
public string name { get; set; }
public T value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在我想创建一个IList<Setting<T>>
但是有不同类型Setting<T>
的T,我想要eG
List<Setting<T>> settingsList;
settingsList.Add(new Setting<int>());
settingsList.Add(new Setting<string>());
Run Code Online (Sandbox Code Playgroud)
我试过IList<Setting<T>>
但这似乎不可能,因为编译器找不到Type T
.
我知道我可以使用对象,但我希望它是强类型的.所以我的问题是,是否有可能让这个工作.
我试图IList<T>
通过他们的类型比较两个.两个列表都相同T
,因此我认为它们应该具有相同的类型.
在工具提示中的Visual Studio中的调试模式中,我可以读取两者的类型,它是相同的.
但Equals()
蚂蚁==
运营商同时返回false
.
任何人都能解释这种疲惫的行为吗?
小例子:
class Program
{
static void Main(string[] args)
{
IList<string> list1 = new List<string>();
IList<string> list2 = new List<string>();
var type1 = list1.GetType();
var type2 = typeof(IList<string>);
if (type1.Equals(type2))
{
Console.WriteLine("equal");
}
else
{
Console.WriteLine("non equal");
}
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
==>不等于
编辑: 我写了一个不好的例子,这个显示了我尝试的方式.
我正在使用.Net 3.5
c# ×6
wpf ×6
.net ×5
wpf-controls ×3
datagrid ×2
binding ×1
code-golf ×1
color-space ×1
colors ×1
converter ×1
events ×1
execution ×1
generics ×1
optimization ×1
silverlight ×1
winapi ×1
wpfdatagrid ×1
wpftoolkit ×1
xaml ×1