Locations of visitors to this page


WPF OneWay Binding Part 1

Onteora Software

Ken Tucker's Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

WPF OneWay Binding Part 1

WPF OneWay Binding Part 1



Windows Presentation Foundation (WPF) foundation is for building applications and experiences in Windows Vista that blend the application UI, documents, and media content. In this series of blog entries we willl start to explore some of the improvements to data binding in WPF. You will need to have the .Net Framework 3.0, Windows Vista SDK, and Visual Studio 2005 extensions for WPF and WCF installed for this sample.


For this example we will start off with a Windows Application (WPF). In the forms XMAL we will add a stack panel to hold a label and scrollbar. The label's content will be bound to the scrollbar's value so as we move the scrollbar the value will be displayed in the label.


In the Lets set up a DataContext which is bound to the scrollbar .


      <Label   HorizontalAlignment="Center" DataContext="{Binding ElementName=hscroll, Mode=OneWay}"

Now we can bind the label's content to the scrollbars value


      <Label   HorizontalAlignment="Center" DataContext="{Binding ElementName=hscroll, Mode=OneWay}"
               Content="{Binding Path=Value}"  />



The complete XMAL for the Window


<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPFOneWayBind" Height="300" Width="300"
    >
    <Grid>
      <StackPanel>
      <ScrollBar Name="hscroll" Maximum="100"  Minimum="1" SmallChange="1" LargeChange="10" Orientation="Horizontal"></ScrollBar>
      <Label   HorizontalAlignment="Center" DataContext="{Binding ElementName=hscroll, Mode=OneWay}"
               Content="{Binding Path=Value}"  />
      </StackPanel>
    </Grid>
</Window>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: WPF
Posted by Ken Tucker on Friday, April 06, 2007 10:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Comments are closed