0

I have an UserControl with DependencyProperty SliderZoom which is a typeof Slider. In my window I have an control who's name is SliderZoom and i want to use binding on it.

Is that even possible? if not how can i achieve something close to this?

Window Code

<local:NewSlider
  SliderZoom="{Binding SliderZoom}">
</local:NewSlider>

 <Slider x:Name="SliderZoom"
                Width="150"
                Interval="1"
                Maximum="10"
                Minimum="0" />

UserControl NewSlider Code

    public Slider SliderZoom
    {
        get { return (Slider)GetValue(ZoomSliderProperty); }
        set { SetValue(ZoomSliderProperty, value); }
    }

    public static readonly DependencyProperty ZoomSliderProperty =
    DependencyProperty.Register("SliderZoom", typeof(Slider), typeof(NewTimeSlider),
    new PropertyMetadata(OnZoomSliderChanged));

    private static void OnZoomSliderChanged(DependencyObject dependencyObject,DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
    {
        var AdvanceTimeSlider = dependencyObject as NewTimeSlider;

        if (AdvanceTimeSlider != null)
        {
            AdvanceTimeSlider.OnZoomSliderChanged(dependencyPropertyChangedEventArgs);
        }
    }


    private void OnZoomSliderChanged(DependencyPropertyChangedEventArgs e)
    {
        SliderZoom.ValueChanged += SliderZoom_OnValueChanged;
        var _thumb = SliderTimeLine.Template.FindName("Thumb", SliderZoom) as Thumb;
        _thumb.DragCompleted += SliderZoom_OnDragCompleted;
        _thumb.DragStarted += SliderZoom_OnDragStarted;
    }
4

1 回答 1

0

你真的需要在这里绑定吗?为什么不只设置SliderZoom属性值?

<local:NewSlider>
    <local:NewSlider.SliderZoom>
        <Slider x:Name="SliderZoom"
                    Width="150"
                    Interval="1"
                    Maximum="10"
                    Minimum="0" />
    </local:NewSlider.SliderZoom>
</local:NewSlider>
于 2013-11-12T05:35:17.247 回答