Silverlight / WPF - i have binded the slider as a item to the listbox value change is not detected for 1st tim

Asked By Ramachandran on 27-Jun-12 03:44 AM
i have binded the slider as a item to the Silver light  listbox, the slider value is  binded properly during the load time from the database. but when i changed the slider value from its valuechanged events its values are not affected for the first time.

i.e the value of the slider is binded to the datagrid. when i changed the slider value its changed value to be binded  in the silverlight datagrid. but it is affecting for second time. during first time its not affected...
here is my code:---


   <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 RelativeSource={RelativeSource AncestorType=ScrollViewer}, Path=DataContext.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" ToolTipService.ToolTip="{Binding ElementName=WireFrameSlider,Path=Value,StringFormat=\{0:n2\}}"  Height="27" Width="90"
                              Name="txtblkEffectPercentValue"/>

      <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='#.##'}" ToolTipService.ToolTip="{Binding Jan,StringFormat='#.##'}" Header="Jan"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Feb,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Feb,StringFormat='#.##'}" Header="Feb"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Mar,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Mar,StringFormat='#.##'}" Header="Mar"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Apr,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Apr,StringFormat='#.##'}" Header="Apr"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding May,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding May,StringFormat='#.##'}" Header="May"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Jun,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Jun,StringFormat='#.##'}" Header="Jun"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Jul,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Jul,StringFormat='#.##'}" Header="Jul"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Aug,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Aug,StringFormat='#.##'}" Header="Aug"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Sep,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Sep,StringFormat='#.##'}" Header="Sep"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Oct,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Oct,StringFormat='#.##'}" Header="Oct"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Nov,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Nov,StringFormat='#.##'}" Header="Nov"></sdk:DataGridTextColumn>
          <sdk:DataGridTextColumn Binding="{Binding Dec,StringFormat='#.##'}" ToolTipService.ToolTip="{Binding Dec,StringFormat='#.##'}" Header="Dec"></sdk:DataGridTextColumn>
        </sdk:DataGrid.Columns>

here applydatalist are the values of slider values.........
Neha Garg replied to Ramachandran on 27-Jun-12 04:11 AM
Hello

See the below code to handle the slider change event....



XAML:
 
<StackPanel>
  <Slider x:Name="rating" Minimum="1" Maximum="5" SmallChange="1" Value="1" Width="200" ValueChanged="Slider_ValueChanged" />
  <TextBlock x:Name="displayRating" />
</StackPanel>
 
C#:
 
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
  string rateAvg = e.NewValue.ToString();
  
  try
  {
    displayRating.Text = rateAvg;
  }
  catch { }
}

Neha Garg replied to Ramachandran on 27-Jun-12 04:17 AM
Also, See the examples given on the below links:

 

http://www.c-sharpcorner.com/uploadfile/mamta_m/slider-control-in-silverlight-3/

 

http://stackoverflow.com/questions/10407419/bind-slider-value-to-progressbar-effectively