Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
360
Frustration trying to bind NumberOfTickMarks in XamNumericSlider
posted

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>