代码之家  ›  专栏  ›  技术社区  ›  David Lee

工具提示中带有日期的WPF MVVM MahApps范围滑块

  •  1
  • David Lee  · 技术社区  · 7 年前

    https://mahapps.com/docs/controls/rangeslider 在WPF MVVM应用程序中。目前,工具提示显示数值,我希望显示一个日期。

    WPF Slider and dates

        public class HourToDateConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                object result = DependencyProperty.UnsetValue;
                if (value is double)
                    result = DateTime.Now.Date.AddHours((double)value);
                return result;
            }
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    

    我已经成功地获得了 TextBlock 然而,为了显示日期范围,我想在工具提示中显示相同的日期范围。

    这可能吗?提前谢谢。

    1 回复  |  直到 4 年前
        1
  •  3
  •   mm8    7 年前

    尝试设置 AutoToolTipTextConverter 属性设置为转换器类的实例:

    <Grid>
        <Grid.Resources>
            <local:HourToDateConverter x:Key="HourToDateConverter" />
        </Grid.Resources>
        <Controls:RangeSlider x:Name="xxx"
                    Minimum="10"
                    Maximum="100"
                    AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="2" MoveWholeRange="True"
                    IsSnapToTickEnabled="True" IsMoveToPointEnabled="True" ExtendedMode="True"
                    AutoToolTipTextConverter="{StaticResource HourToDateConverter}">
        </Controls:RangeSlider>
    </Grid>