Silverlight / WPF - what is ancestor binding and what is relative source binding in silverlight 5 using jounce

Asked By Ramachandran on 29-Jun-12 03:06 AM
what is ancestor binding and ancestor level and relative source binding in silverlight 5.. i have binded the listbox with in the scrollviewer and i am having the slider as the item in the listbox when even i scroll the scroll viewer vertically up and down my slider values are changed... plse tell what is the problem with this. this is my xaml code. where i want to change this to not to affect the slider value when scrolling up and down. here is my xaml code.

<navigation:Page xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="MediaForecaster.Views.FormDisplayApplyFactors"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:ViewModels="clr-namespace:MediaForecaster.ViewModels"
       xmlns:Regions="clr-namespace:Jounce.Regions;assembly=Jounce"
       mc:Ignorable="d"
       xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
       xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        Width="Auto" Height="Auto"
       Title="FormDisplayApplyFactors Page">
    <Grid x:Name="LayoutRoot">
      <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="30"/>
        <RowDefinition Height="50"/>
        <RowDefinition Height="50"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>
      <StackPanel Grid.Row="0" Orientation="Horizontal">
        <TextBlock  Margin="45,-50,0,0"   Text="Apply Factors To" />
        <TextBlock  Margin="10,-50,0,0"  Foreground="Red" FontStyle="Italic"  Text="{Binding resultname,Mode=TwoWay}" />
        <!--<TextBox Width="120" Height="25"  Margin="10,-110,0,0"  />-->
        <TextBlock  Margin="10,-50,0,0"   Text="for Year" />
        <TextBlock Foreground="Red" FontStyle="Italic"   Margin="10,-50,0,0" Text="{Binding resultyear, Mode=TwoWay}"/>
        <!--<ComboBox  Margin="10,-110,0,0" Width="120" Height="25"/>-->
      </StackPanel>
      <Grid Grid.Row="1">
        <StackPanel >
          <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="0,-20,0,0" HorizontalScrollBarVisibility="Auto">
            <ScrollViewer.Content>
              <ListBox  Background="AliceBlue" Height="250" Width="960" ItemsSource="{Binding ListboxSource,Mode=TwoWay}">
                <ListBox.ItemTemplate>
                  <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                      <Border Margin="5" Padding="1"
                          BorderBrush="SteelBlue" BorderThickness="1" CornerRadius="15">
                        <Grid>
                          <Grid.RowDefinitions>
                            <RowDefinition Height="2*"/>
                          </Grid.RowDefinitions>
                          <Grid Grid.Row="0">
                            <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="50"/>
                              <ColumnDefinition Width="200"/>
                              <ColumnDefinition Width="70"/>
                              <ColumnDefinition Width="110"/>
                              <ColumnDefinition Width="110"/>
                              <ColumnDefinition Width="50"/>
                              <ColumnDefinition Width="100"/>
                              <ColumnDefinition Width="50"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                              <RowDefinition Height="40"/>
                              <RowDefinition Height="40"/>
                              <RowDefinition Height="40"/>
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Margin="3,0,0,0" Text="Name" Grid.Column="0" Height="27" Width="35" HorizontalAlignment="Left" />
                            <TextBox  Grid.Row="0" Margin="0,0,0,0"  Text="{Binding ApplyFactorvalue,Mode=TwoWay}" IsEnabled="False" Grid.Column="1" Height="27" Width="150" HorizontalAlignment="Left"  Name="txtName"/>
                            <TextBox Grid.Row="1"  Grid.Column="1" Margin="0,0,0,0" HorizontalAlignment="Left" Width="150"  IsEnabled="False"  Height="80" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Name="txtdesc" Text="{Binding Description, Mode=TwoWay}" Grid.RowSpan="2" AcceptsReturn="True"/>
                            <TextBlock Name="txtblkFrom" HorizontalAlignment="Left" Margin="0,0,0,0" Grid.Row="1" Grid.Column="2" Width="50" Text="From" Height="27"/>
                            <TextBlock Name="txtblkTo"  HorizontalAlignment="Left" Margin="0,0,0,0" Grid.Row="2" Grid.Column="2" Width="50" Text="To" Height="27"/>
                            <ComboBox Name="ddlfrommonth"  Margin="0,0,0,0" HorizontalAlignment="Left" Width="100" Grid.Row="1" Grid.Column="3" Height="27"
                                ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ScrollViewer}, Path=DataContext.FromMonthList}"
                                DisplayMemberPath="MonthName"
                                  SelectedValuePath="MonthName"
                                SelectedValue="{Binding FromMonth,Mode=TwoWay}">
                              <i:Interaction.Triggers>
                                <i:EventTrigger EventName="SelectionChanged">
                                  <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=ScrollViewer}, Path=DataContext.CalculateConsolidatedFactors}"/>
                                </i:EventTrigger>
                              </i:Interaction.Triggers>
                            </ComboBox>
                            <ComboBox Name="ddlTomonth"  Margin="0,0,0,0" HorizontalAlignment="Left" Width="100" Grid.Row="2" Grid.Column="3" Height="27"
                               ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ScrollViewer}, Path=DataContext.ToMonthList}"
                                DisplayMemberPath="MonthName"
                                  SelectedValuePath="MonthName"
                                SelectedValue="{Binding ToMonth,Mode=TwoWay}" >
                              <i:Interaction.Triggers>
                                <i:EventTrigger EventName="SelectionChanged">
                                  <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=ScrollViewer}, Path=DataContext.CalculateConsolidatedFactors}"/>
                                </i:EventTrigger>
                              </i:Interaction.Triggers>
                            </ComboBox>
                            <TextBlock FontWeight="Bold" Text="Max%Min%" Grid.Row="0" Grid.Column="4"  Height="27" Width="90" Name="txtblkMaxMinPercent"/>
                            <TextBox Name="MaxPercen" IsEnabled="False"  MaxLength="4"  Grid.Row="1" Grid.Column="4" Width="90" Height="27" Text="{Binding MaxValue,Mode=TwoWay}"/>
                            <TextBox Name="MinPercen" IsEnabled="False" MaxLength="3" Grid.Row="2"  Grid.Column="4" Width="90" Height="27"   Text="{Binding MinValue,Mode=TwoWay}"/>
                            <!--DisplayMemberPath="Name" SelectedValuePath="ID" ItemsSource="{Binding Path=EntityObjects, Mode=TwoWay}" SelectedItem="{Binding Path=ToMonthPercentSelectValue,Mode=TwoWay}"/>-->
                            <Slider  Name="WireFrameSlider" Orientation="Vertical"  Minimum="{Binding ElementName=MinPercen,Path=Text, Mode=TwoWay}" Maximum="{Binding ElementName=MaxPercen,Path=Text, Mode=TwoWay}" Value="{Binding FactorPercent,Mode=TwoWay}"   Height="120" Grid.Row="0" Grid.Column="5" Grid.RowSpan="3"  Width="30" Cursor="Arrow">
                              <i:Interaction.Triggers>
                                <i:EventTrigger EventName="ValueChanged">
                                  <i:InvokeCommandAction Command="{Binding CalculateConsolidatedFactors}"/>
                                </i:EventTrigger>
                              </i:Interaction.Triggers>
                            </Slider>
                            <TextBlock FontWeight="Bold" Text="Effect" Grid.Row="0" Grid.Column="6"  Height="27" Width="90" Name="txtblkEffect"/>
                            <TextBlock                             
                              Text="{Binding ElementName=WireFrameSlider,Path=Value, Mode=TwoWay, StringFormat=\{0:n2\}}"
                              Grid.Row="1" Grid.Column="6"  Height="27" Width="90"
                              Name="txtblkEffectPercentValue"/>
                            <CheckBox Margin="0,0,0,0" HorizontalAlignment="Left" Grid.Column="7" Grid.Row="1" Command="{Binding RelativeSource={RelativeSource AncestorType=ScrollViewer}, Path=DataContext.CalculateConsolidatedFactors}"   IsChecked="{Binding ApplyFactorCheckbox,Mode=TwoWay}" Height="40"  Width="50" />
                          </Grid>
                        </Grid>
                      </Border>
                    </StackPanel>
                  </DataTemplate>
                </ListBox.ItemTemplate>
              </ListBox>
            </ScrollViewer.Content>
          </ScrollViewer>
        </StackPanel>
      </Grid>
      <TextBlock Text="Summary" Foreground="Red" Grid.Row="2" Margin="70,0,0,0"/>
      <sdk:DataGrid Grid.Row="3" Name="myDataGrid" ItemsSource="{Binding ApplyDataList,Mode=TwoWay}" Background="Yellow" Foreground="blue" Height="100"  Margin="0,0,0,0" Width="900" AutoGenerateColumns="False" >
        <sdk:DataGrid.Columns>
          <sdk:DataGridTextColumn Binding="{Binding Jan,StringFormat='#.##'}" Header="Jan"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Feb,StringFormat='#.##'}" Header="Feb"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Mar,StringFormat='#.##'}" Header="Mar"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Apr,StringFormat='#.##'}" Header="Apr"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding May,StringFormat='#.##'}" Header="May"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Jun,StringFormat='#.##'}" Header="Jun"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Jul,StringFormat='#.##'}" Header="Jul"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Aug,StringFormat='#.##'}" Header="Aug"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Sep,StringFormat='#.##'}" Header="Sep"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Oct,StringFormat='#.##'}" Header="Oct"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Nov,StringFormat='#.##'}" Header="Nov"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Dec,StringFormat='#.##'}" Header="Dec"></sdk:DataGridTextColumn>
        </sdk:DataGrid.Columns>
      </sdk:DataGrid>
      <Button Content="Apply" Command="{Binding Path=NavigateRevenueImpact}"  Margin="570,-50,0,0" Width="100" Height="30" Grid.Row="4"  />
      <Button Content="Cancel" Command="{Binding Path=Cancel}"  Margin="800,-50,0,0" Width="100" Height="30" Grid.Row="4"  />
    </Grid>
</navigation:Page>