Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:45+00:00 2026-05-26T06:45:45+00:00

Need to format a string in a ListView GridView in code behind. XAML is

  • 0

Need to format a string in a ListView GridView in code behind. XAML is not an option as the data and columns are created in code.

The XAML version of the desired date format is:

   <TextBlock TextWrapping="NoWrap" Text="{Binding Path=DateTime, Mode=OneWay, StringFormat={}{0:yyyy/MM/dd hh:mm tt}}" />

In this case I cannot use XAML as the number of columns varies and the columns that need to display a date in that format varies. I just cannot figure out how to apply that date format in code behind. Below is working code behind to build the columns.

    GridViewColumn gvc;
    GridViewColumnHeader gvch;
    Binding gvBinding;
    DataTemplate template;
    FrameworkElementFactory textblock;

    // Data Column
    gvc = new GridViewColumn();
    gvch = new GridViewColumnHeader();
    gvch.Content = SF.DispName;
    gvch.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
    gvch.VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom;
    gvch.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
    gvc.Header = gvch;
    gvBinding = new Binding();
    gvBinding.Mode = BindingMode.OneWay;
    gvBinding.Path = new PropertyPath("[" + (sDocBaseResultDocsFieldsIndex * 2).ToString() + "]");
    template = new DataTemplate();
    textblock = new FrameworkElementFactory(typeof(TextBlock));
    textblock.SetValue(TextBlock.TextProperty, gvBinding);
    // textblock.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.WordEllipsis);
    template.VisualTree = new FrameworkElementFactory(typeof(Grid));
    template.VisualTree.AppendChild(textblock);
    gvc.CellTemplate = template;
    gvSrchResultsScore.Columns.Add(gvc);

    sDocBaseResultDocsFieldsIndex++;

What I need to add is something like below but cannot figure it out. I have tried every permutation of {}{0:yyyy/MM/dd hh:mm tt}} that I can think of.

    if (sDocBaseResultDocsFieldsIndex == 12) gvBinding.StringFormat = "Help";   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:45:45+00:00Added an answer on May 26, 2026 at 6:45 am

    The empty braces {} that you use in the xaml are an escape sequence so the format is not interpreted as a markupextension by the parser. You don’t need them in the codebehind – try this:

    gvBinding.StringFormat = "{0:yyyy/MM/dd hh:mm tt}";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using an infragistics webgrid and need to format a currency string. For
I need to format a decimal value into a string where I always display
string format is always like this FirstName=ABC;LastName=XZY;Username=User1;Password=1234. I need the only UserName value (which
I have one JSON that is coming in a string format. I need to
I need to convert a string to a monetary format of {###}.###.###,## that is
I need a method to return a random string in the format: Letter Number
I need to remove the following format from the end of a string in
Say, I have a string that I need to verify the correct format of;
I need to find out how to format numbers as strings. My code is
I need to format a string in a custom number with the mask: 0000000-00.0000.0.00.0000.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.