向用户控件公开自定义 DateTime 属性
我正在开发一个日历,其中我的日子是这样排列的
<Label Grid.Row="1" Grid.Column="1" Content="{Binding Path=SundayLabel, FallbackValue=Sunday}" Style="{StaticResource ResourceKey=DayLabelStyle}" />
<custom:DayDisplay Grid.Row="2" Grid.Column="1" x:Name="SundayDisplay" />
<Label Grid.Row="1" Grid.Column="2" Content="{Binding Path=MondayLabel, FallbackValue=Monday}" Style="{StaticResource ResourceKey=DayLabelStyle}" />
<custom:DayDisplay Grid.Row="2" Grid.Column="2" x:Name="MondayDisplay" />
等等。 DayDisplay 是一个自定义 WPF 控件。 包含所有这些 DayDisplays 的控件需要某种方式来设置带有 DateTime 的各个日期,最好是从代码隐藏。
有没有某种方法可以在我的 DayDisplay 视图中公开自定义属性,以便我可以执行以下操作:
<custom:DayDisplay Grid.Row="2" Grid.Column="2" x:Name="MondayDisplay" x:Day="{MondayDateTime}"/>
最好我想将所有自定义:DayDisplay 对存储在字典中,并在可能的情况下自动生成它们。非常感谢任何帮助:)
谢谢, 尼克拉斯
I am developing a calendar where my days are aligned like this
<Label Grid.Row="1" Grid.Column="1" Content="{Binding Path=SundayLabel, FallbackValue=Sunday}" Style="{StaticResource ResourceKey=DayLabelStyle}" />
<custom:DayDisplay Grid.Row="2" Grid.Column="1" x:Name="SundayDisplay" />
<Label Grid.Row="1" Grid.Column="2" Content="{Binding Path=MondayLabel, FallbackValue=Monday}" Style="{StaticResource ResourceKey=DayLabelStyle}" />
<custom:DayDisplay Grid.Row="2" Grid.Column="2" x:Name="MondayDisplay" />
and so forth. DayDisplay is a custom WPF control.
The control containing all theese DayDisplays needs some way to set the individual days with a DateTime preferably from code behind.
Is there some way to expose a custom property in my DayDisplay view so i could do something like:
<custom:DayDisplay Grid.Row="2" Grid.Column="2" x:Name="MondayDisplay" x:Day="{MondayDateTime}"/>
Preferably i would like to store all custom:DayDisplay pairs in a Dictionary and have them autogenerated also if it is possible. Any help is greatly appreciated :)
Thanks,
Niklas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在控件上公开一个 DateTime 依赖属性,如下所示:
如果您希望自动生成它,您应该做的是拥有一个包含您的 DayControl 的 ItemsControl,如下所示:
然后从后面的代码对其进行 DataBind:
you should expose a DateTime dependency property on the control, done like so:
if you want this to be auto generated, what you should do is have an ItemsControl that contains this dayControl of yours, like so:
and then DataBind it from code behind: