【发布时间】:2019-11-04 15:24:49
【问题描述】:
我有一个自定义 WPF UserControl,它在其中使用 DatePicker。我正在使用提供的答案 at this SO article
设置 DatePicker 的显示格式<Style TargetType="{x:Type DatePickerTextBox}" BasedOn="{StaticResource {x:Type DatePickerTextBox}}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<TextBox x:Name="PART_TextBox"
Text="{Binding Path=SelectedDate, StringFormat='dd-MM-yy', RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我想为控件的不同实例使用不同的格式字符串,所以我想在将 UserControl 添加到表单时以某种方式提供格式,例如
<basecontrols:CustomControl
LabelWidth="{StaticResource LabelColumnWidth}"
Label="Custom Information"
DateDisplayFormat="dd-MMMM-yyyy"
/>
Label 和 LabelWidth 是自定义 UserControl 的 Dependancy 属性。
是否可以将 StringFormat 绑定到控件属性,当它位于 Binding 中时?如果没有,有没有办法做我想做的事?
希望这是有道理的
【问题讨论】:
标签: c# wpf wpf-controls