首页 > 解决方案 > SliderThumbStyle 内的文本

问题描述

所以这是我的SliderThumbStyle Style

<Style x:Key="SliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Grid>
                        <Border Name="outerBorder"
                                Background="{DynamicResource LabelDisableForegroundColor}"
                                BorderBrush="{DynamicResource LabelDisableForegroundColor}"
                                Height="20"
                                Width="20"
                                Opacity="1" 
                                BorderThickness="2"
                                CornerRadius="8"/>
                        <TextBlock x:Name="sliderValue"
                                   FontSize="11"
                                   Foreground="Silver"
                                   Text="{Binding }"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

正如你所看到的,我在里面放了Thumb一个简单TextBlock的 in oder 来查看当前Slider value

我需要在 Text 中输入的内容property

Text="{Binding }"

标签: wpfsliderstyles

解决方案


Thumb如果是 的视觉子级,这应该可以工作Slider

<TextBlock Text="{Binding Value, RelativeSource={RelativeSource AncestorType=Slider}}" />

推荐阅读