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 8102739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:19:17+00:00 2026-06-05T23:19:17+00:00

I have a custom ItemTemplate for a ListBox and I need to bind a

  • 0

I have a custom ItemTemplate for a ListBox and I need to “bind” a TextBlock to some special method / property.

My ListBox Source is an ObservableCollection<SearchResultItem>. SearchResultItem containing some properties.

The text need to change based on the value of another object. E.G if this object equals “foo” I need the text value to call the method GetProperty("foo") on the SearchResultItem to get the correct value.

Here is a sample of code:

<DataTemplate>
..
//Here is a Label bound to the Date Property of the SearchResultItem
<Label Margin="2,2,2,0" Grid.Row="0" Grid.Column="2" Content="{Binding Path=Date}" HorizontalAlignment="Right" HorizontalContentAlignment="Right" />
//Here is the textblock that needs to call the method with the parameter based on the value of the other object.
<TextBlock Margin="2,2,2,0" TextTrimming="CharacterEllipsis"  Grid.Row="0" Grid.Column="1" Text="I need some help there" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Black"/>
..
</DataTemplate>

Do you have any idea on how to do that or a better way to do it?

Edit:

-Let’s assume SearchResultItem comes from an external library and only exposes the GetProperty method.

-Let’s say the “foo” value comes from ConfigurationManager.AppSettings["propertyName"]; if it helps.

  • 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-06-05T23:19:19+00:00Added an answer on June 5, 2026 at 11:19 pm

    OK, because your properties never change, here’s one solution. You can do this via another property on your SearchResultItem class:

    public string MyTextBinding
    {
        get 
        {
            return myDictionary.ContainsKey("foo") ? return myDictionary["foo"] : return "myDictionary doesn't contain foo"; 
        }
    }
    

    Then just bind your textbox to this property:

    <DataTemplate>    
        <Label Margin="2,2,2,0" Grid.Row="0" Grid.Column="2" Content="{Binding Path=Date}" HorizontalAlignment="Right" HorizontalContentAlignment="Right" />
        <TextBlock Margin="2,2,2,0" TextTrimming="CharacterEllipsis"  Grid.Row="0" Grid.Column="1" Text="{Binding Path=MyTextBinding, Mode=OneWay}" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Black"/>
    </DataTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox which is bound to my custom class ObservableCollection<FieldPropertyItem> _fieldOrderCollection`; internal
I have a ListBox that uses a custom control as the ListBox.ItemTemplate DataTemplate. I
I have a custom UserControl which has a DependencyProperty ItemTemplate of type DataTemplate. I
I have custom map image with specific height and width. i need to map
I have a ListBox that uses a WrapPanel for its ItemsPanel , a custom
I have ListBox with custom template, how do programmatically scroll it down to bottom?
I have a custom class named BlinkingLight. I also have a static ObservableCollection BlinkingLightCollection.
I have a custom user control which has some textboxes and some buttons. In
I have a custom UserControl that consists of a ListBox with a DataTemplate .
I have a ListBox in a WP7 app page which I bind to a

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.