0

I'm trying to set the Text property of a TextBox to an static property which of type double. But obviously I'm getting an error:

Invalid member type: expected type is 'string' actual type is 'double'

because it only accepts an string. How can I fix this? And why I don't get this error when I Bind to a non-static property which is also double?

<TextBox Text="{x:Static building:Building.FoundationHeight}"/>

Building is an static class and FoundationHeight is static property of type double.

Solution:

The question is a duplicate, I'll post the answer specific to this question here anyway:

<TextBox Text="{Binding Source={x:Static building:Building.FoundationHeight}, Mode=OneWay}"/>
Vahid
  • 5,144
  • 13
  • 70
  • 146
  • 1
    You do not get this error when using a `{Binding}` because [`System.Windows.Data.Binding`](http://msdn.microsoft.com/en-us/library/system.windows.data.binding.aspx) is a much more complex class that can handle (among other things) type conversions, while [`System.Windows.Markup.StaticExtension`](http://msdn.microsoft.com/en-us/library/system.windows.markup.staticextension.aspx) does not. – Jean Hominal Aug 28 '14 at 07:47
  • @JeanHominal Thanks, I was just curious, if this can be done this way? – Vahid Aug 28 '14 at 07:50
  • Thank you so much, Sheridan. The link you posted solved the problem. – Vahid Aug 28 '14 at 07:54
  • @Vahid Please do not add the answer to your question, but as an _answer_. After 48 hours, you will also be able to accept it. – Mathias Müller Aug 28 '14 at 08:17
  • @MathiasMüller Sure, I thought since this is a duplicate, now one will want it. – Vahid Aug 28 '14 at 08:19
  • 1
    @Vahid Ah, my bad - if it stays closed you cannot add answers.. apologies! – Mathias Müller Aug 28 '14 at 08:20
  • @MathiasMüller I just realized that too :( – Vahid Aug 28 '14 at 08:23

0 Answers0