开发者

Wpf - Combobox Binding to a DateTime ArrayList

I have a static ArrayList of DateTimes

<Window.Resources>
    <col:ArrayList x:Key="startHours">
        <sys:DateTime>0:00</sys:DateTime>
        <sys:DateTime>0:30</sys:DateTime>
        <!-- .... -->
    </col:ArrayList>
</Window.Resources>

I want to fill a combobox with hour:minute formatted dates, so I do

<Com开发者_Go百科boBox x:Name="cmbFinish" 
          ItemsSource="{Binding Source={StaticResource startHours}}" 
          ItemStringFormat="t"/>

The Items are formatted ok - hour:minute, but when I select an item, the cmbFinish.Value has the default DateTime.ToString() format. What am I missing? I need the cmbFinish.Value to be in hour:minute format.


I don't see a Value property in ComboBox class. Were you thinking about the SelectedValue property? In this case cast its value to a DateTime (DateTime)cmbFinish.SelectedValue that you can then convert to the string format you want.


I'm sorry... My combobox has a IsEditable(I forgot to add it into the question) property set to True. According to social msdn in this case .SelectedValue will pick up the source value, even if it has a converter applied.

If the IsEditable property is set to False, there is no difference in the Items format and .SelectedValue format. Right now I think the best way is to bind to a converted into strings ArrayList.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜