开发者

Not Binding WpfToolKit:dataPicker through Converter

开发者 https://www.devze.com 2023-01-19 05:27 出处:网络
ConvertDateTime - return good string \"01.10.2010\" but datapicker not binding. if we replace datap开发者_Go百科icker on textbox - all works well

ConvertDateTime - return good string "01.10.2010" but datapicker not binding.

if we replace datap开发者_Go百科icker on textbox - all works well

help me, code:

add:

 xmlns:loc="clr-namespace:StoreBags"

add:

 <loc:ConvertDateTime x:Key="conkey"/>

xaml add:

 <my:DataGridTemplateColumn Header="Дата" Width="100">
        <my:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <DockPanel>
                    <my:DatePicker Text="{Binding date, Converter={StaticResource conkey}}" x:Name="p_datePicker"/>
                </DockPanel>
            </DataTemplate>
        </my:DataGridTemplateColumn.CellTemplate>
    </my:DataGridTemplateColumn>

Converter:

public class ConvertDateTime : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                DateTime date = (DateTime)value;
                return date.ToShortDateString().ToString(); // return "01.10.2010"
            }
            catch { return null; }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = value as string;
            DateTime resultDateTime;
            if (DateTime.TryParse(strValue, out resultDateTime))
            {
                return resultDateTime;
            }
            return DependencyProperty.UnsetValue;
        }
    }


Try binding to the SelectedDate property instead

SelectedDate="{Binding date, Converter={StaticResource conkey}}"
0

精彩评论

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