WPF造型滑块Thumb [英] WPF Styling Sliders Thumb

查看:80
本文介绍了WPF造型滑块Thumb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我的目标是创建自定义滑块,其中滑块的当前值显示在其可拖动的拇指内(在文本块内).我在wpf中还很新,但是我认为它可以用于样式吗?

这是我目前的拇指样式.问题是我无法将文本框的Text属性绑定到滑块的Value属性(滑块样式x:key为MySlider).还是事件正确的方法...

Hi All!

My goal is to create custom slider where sliders current value is shown inside its dragable thumb (inside textblock). Im quite new in wpf, but I think it is doable with styles?

Here is my current thumbstyle. The problem is that I cannot bind my textbox Text property to sliders Value property (slider style x:key is MySlider). Or is it event right way to do it...

<!--Simple SliderThumb - The Thumb is the draggable part of a Slider--> 
<Style x:Key="MySliderThumb" d:IsControlPart="True" TargetType="{x:Type Thumb}">
<setter property="SnapsToDevicePixels" value="true"></setter>
<setter property="Height" value="50"></setter>
<setter property="Width" value="50"></setter>
<setter property="Template">
  <setter.value>
    <controltemplate targettype="{x:Type Thumb}">
      <grid>                        
         <border borderbrush="{DynamicResource normalBorderBrush}" borderthickness="2">

         <textblock text="{Binding ElementName=MySlider, Path=Value}"></textblock> <!--THIS WONT WORK. HOW TO BIND MY SLIDER STYLE x:key="MySlider" AND ITS CURRENT VALUE?-->          
         </border>
     </grid> 
                </controltemplate>
            </setter.value>
        </setter>
    </Style>



希望你有主意:)

干杯!



Hope you got idea :)

Cheers!

推荐答案

尝试
<textblock text="{TemplateBinding Value}" />



请注意,我不确定使用此控件是否确实可行(我没有尝试过,也没有过多使用WPF/Silverlight).但这似乎是适当的绑定路径.



Note that I''m not sure if this is actually possible with this control (I''ve not tried and I don''t use WPF/Silverlight much). That seems like the appropriate binding path though.


这篇关于WPF造型滑块Thumb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆