Public · Protected · Private
Binding modes
Type: Public  |  Created: 2012-09-02  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • OneWay   source --> target
    TwoWay    source <-> target
    OneTime    source -> target only once
    OneWayToSource  source <- target
    Default  is OneWay   (except for textboxes(it is Twoway for textbox)
    2012-09-02 05:50
  • Simple element binding
    <Slider Name="mySlider"
            Margin="3"
            Minimum="1"
            Maximum="40"
            Value="10"
            TickFrequency="1"
            TickPlacement="TopLeft">
    </Slider>

    <TextBlock Margin="81,126,185,125"
                Text="Simple Text"
                Name="myTextBox"
                FontSize="{Binding ElementName=mySlider, Path=Value, Mode=TwoWay}">
    </TextBlock>

     

    To do samething programmatically

    Binding b = new Binding();
    b.Source = mySlider;
    b.Path = new PropertyPath("Value");
    b.Mode = BindingMode.TwoWay;

    //BindingOperations.ClearAllBindings(myTextBox); // a way to reset
    myTextBox.SetBinding(TextBlock.FontSizeProperty, b);

    2012-09-02 05:58
  • If you are not binding to an element, you are binding to one of the following
    (instead of ElementName=)
    Source. object that's supplying .
    RelativeSource. path or pointer to source object.
    DataContext. finding by nearest parents datacontext object

    Calling system resource/ window resource
        <Window.Resources>
            <FontFamily x:Key="windowResource">sometext</FontFamily>
        </Window.Resources>

    <TextBlock Text="{Binding Source={x:Static SystemFonts.IconFontFamily}, Path=Source}"></TextBlock>
    <TextBlock Text="{Binding Source={StaticResource windowResource},Path=Source}"></TextBlock>

    2012-09-02 06:17
This blog is frozen. No new comments or edits allowed.