JimDel
JimDel

Reputation: 4359

How can I change the values in XAML based on user input from a textBox?

How can I change the values in XAML based on user input from a textBox? I'm just starting off with WPF/Silverlight and like what most people say, there is a steep learning curve. In the code below I get the result in the picture below.

<TextBlock TextWrapping="Wrap" Width="250">
   <Span FontSize="20">2</Span>
   <Span BaselineAlignment="TextTop" FontSize="14">1/2</Span>
</TextBlock>

enter image description here

But I want the fraction to be the result of a computation. Not static like above. Is it possible to take the value of something computed in a .cs file, and add that value as a variable to the XAML file.

Any answers or points in the right direction would be appreciated. Thanks

Upvotes: 0

Views: 1016

Answers (2)

Dylan Meador
Dylan Meador

Reputation: 2401

Use Binding, as H.B. suggested. The end result will look similar to the code snippet below.

<Span Foreground="Gray">
    <Run Text="{Binding Path=yourPath}"/>
</Span>

Upvotes: 0

brunnerh
brunnerh

Reputation: 185170

Have a look (- actually one look will not be enough -) at data binding, you can create a property which holds the value of the fraction and bind the text to that. If you want actual factions like 1/2 you will probably need a proper struct with an approriate ToString override.

Upvotes: 1

Related Questions