Date Converter using WPF

后端 未结 2 1399
闹比i
闹比i 2020-12-18 06:59
public class DateTimeConverter : IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, Sy         


        
2条回答
  •  既然无缘
    2020-12-18 07:35

    You dont need a converter for doing this. You can use the StringFormat in binding itself to format your selected datetime to show just date in mm/dd/yyyy format.

    
    

    I tested with this code and it is working fine. XAML:

    
                
                
                
                    
                        
                    
                
                
                    
                        
                            
                                
                            
                        
                    
                
            
                
            
    

    Model:

        public class TestData
        {
            DateTime start;
            public DateTime Start
            {
                get { return start; }
                set { start = value; }
            }
    
        }
    

    ViewModel has list of TestData to be bound to DataGrid:

    public List TestList { get; set; }
    

提交回复
热议问题