我有一个自定义WPF用户控件,其中使用了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的Dependency属性。
当StringFormat位于Binding中时,是否可以将StringFormat绑定到控件属性?如果没有,有没有办法做我想做的事?
有意义的希望