【问题标题】:Call a Method while Binding Datagrid Column WPF绑定 Datagrid 列 WPF 时调用方法
【发布时间】:2013-01-10 12:29:32
【问题描述】:

在我的 asp.net GridView 中,我使用以下方式转换 GridView 列数据。

<ItemTemplate>
    <asp:Label ID="lb_gvInbox_DelTime" runat="server" Text='<%# this.GetTimeFormat(Eval("Order_Date"))%>'/>
</ItemTemplate>

方法将是

protected string GetTimeFormat(object dateTimeObj)
    {
        DateTime dateTime = (DateTime)dateTimeObj;
        return (dateTime.Date == time.Date) ? dateTime.ToString("hh:mm tt", CultureInfo.InvariantCulture)
                : (dateTime.Year == time.Year) ? dateTime.ToString("MMM dd") : dateTime.ToString("dd/MMM/yy");
    }

我怎样才能在 WPF DataGrid 中这样做??

【问题讨论】:

    标签: c# wpf c#-4.0 wpfdatagrid


    【解决方案1】:

    你要找的是value converters。

     <TextBlock Text="{Binding Order_Date, Converter={StaticResource DateFormatter}}" />
    
    class DateFormatter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
          // your code 
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 2015-07-02
      • 2011-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多