Friday, April 11, 2014

Two way Binding in WPF

This is a program in which i use the slider control in wpf form.
when i increase the slider then the textblock's font size will increase and the value is displayed in another textbox is also increase and vise versa.
But when we also increase the value of the textbox then the slider value will also increase and the text fontsize will also increase and vise versa.

here is the code for that:----

<StackPanel>
            <Slider Name="sliderFontSize" Margin="3" Minimum="1" Maximum="100"  Value="{Binding                                ElementName=txtFontSize, Path=Text, Mode=TwoWay}" TickFrequency="1"                                                    TickPlacement="TopLeft">
             </Slider>
            
             <TextBlock Margin="10" Text="Simple Text" Name="lblSampleText" FontSize="{Binding                                     ElementName=sliderFontSize, Path=Value, Mode=TwoWay}" ></TextBlock>
            
              <TextBox Text="{Binding ElementName=lblSampleText, Path=FontSize, Mode=TwoWay}"                                 Name="txtFontSize"></TextBox>
 </StackPanel>

No comments:

Post a Comment