XAML: Data Binding using one control to control another control

Are you a control freak?  Well not in the way you might be called by your BFF, but rather you like to use controls in Windows Forms, but now you are forced to use XAML because of an evil professor or others, and you are looking into data binding in XAML with C++ and using C++ to write the data binding code would be hard and annoying. 

What if it could be easy?  Ha ha just kidding, everything in C++ is hard!  But this is XAML!  Let’s take a look at a simple XAML data binding that is used commonly in books and articles, and now in VS 2013 will throw a weird exception every time, but didn’t used to (make sure to scroll down to see solution):

<TextBlock x:Name="txtBlock"

FontSize="{Binding Path=Value, ElementName=sizeSlider}"

HorizontalAlignment="Left" Margin="661,150,0,0"

TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"

Height="29" Width="90"/>
      

<Slider x:Name="sizeSlider"

HorizontalAlignment="Left"

Margin="143,150,0,0"

VerticalAlignment="Top"

Width="100"/>

 

Yep, that XAML code will throw an error in VS 2013, but as I recall it didn’t in earlier versions.  But anyway, it throws the error because there is no font with the size of zero, and the slider initial default value is zero. 

So the correct code would look like:

<TextBlock x:Name="txtBlock"

FontSize="{Binding Path=Value, ElementName=sizeSlider}"

HorizontalAlignment="Left" Margin="661,150,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"

Height="29" Width="90"/>
       

<Slider x:Name="sizeSlider"

HorizontalAlignment="Left"

Margin="143,150,0,0"

VerticalAlignment="Top"
               

Width="100"

Minimum="12"

Value="12"/>