views:

570

answers:

2

When data binding two elements together, how can I include the binding information AND text as in the case below where I want my label to say:

The font size is 8.5

<Grid>
    <StackPanel>
        <Slider Name="theSlider" Margin="5" Minimum="8" Maximum="14"></Slider>
        <Label Content="The font size is: {Binding ElementName=theSlider, Path=Value}" FontSize="{Binding ElementName=theSlider, Path=Value}"></Label>
    </StackPanel>
</Grid>

Thank you, so here is the solution using ContentStringFormat in .NET 3.5:

<Grid>
    <StackPanel>
        <Slider Name="theSlider" Margin="5" Minimum="8" Maximum="14"></Slider>
        <Label Content="{Binding ElementName=theSlider, Path=Value}" ContentStringFormat="The font size is {0}."/>
    </StackPanel>
</Grid>
A: 

Use a IValueConverter for the Font-Size.. and use 2 label objects to split the string...

HTH

Arcturus
+1  A: 

Something i learned only a couple of days ago here on stackoverflow :)

If you're using 3.5 SP1 you can use the StringFormat property in your Binding: http://blogs.msdn.com/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx

Bubblewrap