I have a very simple slider shown below. I can bind properties directly on the slider object to my view-model, but no matter how I try to bind the NumberOfTickMarks property in my ig:SliderTickMarks object, I get the following error in my Output:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''. BindingExpression:Path=DataContext.SliderNumTickMarks; DataItem=null; target element is 'SliderTickMarks' (HashCode=23629823); target property is 'NumberOfTickMarks' (type 'Int32')
I have tried setting the binding multiple ways. As you can see in the other properties, they bind to my view-model without a problem as it is the datacontext for my usercontrol. What am I doing wrong?
<ig:XamNumericSlider x:Name="DaySlider" Grid.Row="4"
Margin="3,1,3,1" Orientation="Vertical"
IsDirectionReversed="True" Value="{Binding TotalDaysOnChart}" MinValue="{Binding SliderLowerBound}" MaxValue="{Binding SliderUpperBound}" SmallChange="1"> <ig:XamNumericSlider.TickMarks> <ig:SliderTickMarks NumberOfTickMarks="
{Binding Path=DataContext.SliderNumTickMarks,
RelativeSource={RelativeSource AncestorType=
{x:Type UserControl}}}" /> </ig:XamNumericSlider.TickMarks> </ig:XamNumericSlider>
Hello,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Hi,
I am binding some properties of the slider and every thing works fine. But only NumberOfTickMarks are not binding. ie., binding value of NumberOfTickMarks is 20, but by default it takes 5 (It doesn't throw any error).
And i need one help. For some sliders i don't want TickMarks, how can i achieve this using binding (Actually my sliders are in list box template).
<ListBox ItemsSource="{Binding DataUtil}" VirtualizingStackPanel.VirtualizationMode="Recycling" > <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <ig:XamNumericRangeSlider /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate></ListBox>
Thanks
I have been looking into your issue and I can say that if you want to set the TickMarks externally you should set the SliderTickMarks' UseFrequency Property to False. Also, since the SliderTickMarks element is not part of the VisualTree its Properties can only be bound to a StaticResource like this:
<Grid> <Grid.Resources> <sys:Int32 x:Key="num"> 40 </sys:Int32> </Grid.Resources> <ig:XamNumericSlider x:Name="DaySlider" > <ig:XamNumericSlider.TickMarks> <ig:SliderTickMarks NumberOfTickMarks="{Binding Source={StaticResource num}}" UseFrequency="False" /> </ig:XamNumericSlider.TickMarks> </ig:XamNumericSlider> </Grid>
Hope this helps you.