7

Consider the following bit of code:

<UserControl x:Name=root>
....
    <TextBlock Text="Hello World" Margin="{Binding ElementName=root, Path=LeftButtonMargin}"/>
....
</UserControl>

Now, what is the syntax for setting the FallBackvalue on the Binding?
I've tried some different options already, but I cannot seem to find the correct syntax:

Margin="{Binding ElementName=root, Path=LeftButtonMargin, FallBackValue={}10,10,0,0}"
Margin="{Binding ElementName=root, Path=LeftButtonMargin, FallBackValue={}{10,10,0,0}}"
Margin="{Binding ElementName=root, Path=LeftButtonMargin, FallBackValue={}"10,10,0,0"}"

Or is this not possible at all? Basically, I need these values at design time...

RoelF
  • 7,483
  • 5
  • 44
  • 67

3 Answers3

9

More simple: use single quotes

Margin="{Binding ElementName=root, Path=LeftButtonMargin, FallBackValue='10,10,0,0'}"
serges_newj
  • 795
  • 1
  • 13
  • 23
7

Hopefully works,

<UserControl.Resources>
 <Thickness x:Key="MyMargin" Bottom="5" Top="10">

 </Thickness>
<UserControl.Resources>


<TextBlock Text="Hello World" 
Margin="{Binding ...,FallBackValue={StaticResource MyMargin}}"/>
Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83
2

This is works for me:

    <TextBlock Text="Hello World">
        <TextBlock.Margin>
            <Binding ElementName="root" Path="LeftButtonMargin" FallbackValue="10, 10, 0, 0" />
        </TextBlock.Margin>
    </TextBlock>

but its rather big...

stukselbax
  • 5,855
  • 3
  • 32
  • 54