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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:08:09+00:00 2026-05-23T02:08:09+00:00

I have some stackpanel that have under him 4 textblock that need to show

  • 0

I have some stackpanel that have under him 4 textblock that need to show some information.
I do some binding of the stackpanel ( DataContext ) and binding the textblock with the information that will hold by the object that was bind to the stackpanel.

I wrote the code + xaml and nothing work.
I get exception about format wrong.

The code:

 public partial class SomeDemoClass: UserControl
{
    classObjDemo c1;

    public SomeDemoClass()
    {
        InitializeComponent();

        c1 = new classObjDemo()
        {
              val1 = 5.5,
              val2 = 2.3
        }; 
    }
 }

The xaml ( that match the class ‘SomeDemoClass’ )

   <StackPanel x:Name="LayoutRoot" DataContext="{Binding ElementName=SomeDemoClass, Path=c1">

      <TextBlock Text="{Binding val1, StringFormat={0:F} }" />
      <TextBlock Text="{Binding val2, StringFormat={0:F} }" />


   </StackPanael>
  • 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-23T02:08:09+00:00Added an answer on May 23, 2026 at 2:08 am

    Of you put x:Name=”SomeDemoClass” in the in the op of your xaml and make c1 a public property instead of a field it would work. ElementName references elements in your xaml by name and binding only works on properties and dependency properties.

    <UserControl x:Name="SomeDemoClass" ...
    
    public classObjDemo c1 { get; set; }
    

    Also check your Visual Studio output window for binding errors.

    EDIT

    Also make sure v1 and v2 of the classObjDemo are public properties

    And escape { in your xaml. See http://elegantcode.com/2009/04/07/wpf-stringformat-in-xaml-with-the-stringformat-attribute/

    <TextBlock Text="{Binding val2, StringFormat={}{0:F} }" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that we have the following View: <StackPanel> <TextBlock Text=Some text/> <Image Source={Binding vmImageProp}
Let's say that I have a simple layout such as this: <StackPanel> <TextBlock Text={Binding
I have a stackpanel with some usercontrols that are added or removed during runtime.
I have a WPF StackPanel that looks like this: (some attributes removed that don't
Lets say I have some XAML like this: <StackPanel> <TextBlock Text=Blah Blah Blah />
I have some code that dynamically add button to StackPanel. I want to do
I have the following situation: A stackpanel contains a number of elements, including some
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have found some example code that creates a gradient fill in a WPF

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.