更改DataPager文本 [英] Change DataPager text

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

问题描述

这听起来像是一个奇怪的请求,我不确定是否确实可行,但是我有一个Silverlight DataPager控件,其中说 X第1页,我想更改 Page文本以说些什么

This might sound like a strange request and i'm not sure if it's actually possible, but I have a Silverlight DataPager control where it says "Page 1 of X" and I want to change the "Page" text to say something different.

可以做到吗?

推荐答案

采用DataPager样式默认情况下,有一个名称为CurrentPagePrefixTextBlock的部件,其值为 Page。
您可以参考 http:// msdn .microsoft.com / en-us / library / dd894495(v = vs.95).aspx 了解更多信息。

In DataPager style there is a part by name CurrentPagePrefixTextBlock by default its value is "Page". You can refer http://msdn.microsoft.com/en-us/library/dd894495(v=vs.95).aspx for more info.

解决方案之一是扩展DataPager

One of the solution is to extend DataPager

这是执行此操作的代码

public class CustomDataPager:DataPager
{
    public static readonly DependencyProperty NewTextProperty = DependencyProperty.Register(
    "NewText",
    typeof(string),
    typeof(CustomDataPager),
    new PropertyMetadata(OnNewTextPropertyChanged));

    private static void OnNewTextPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        var newValue = (string)e.NewValue;
        if ((sender as CustomDataPager).CustomCurrentPagePrefixTextBlock != null)
        {
            (sender as CustomDataPager).CustomCurrentPagePrefixTextBlock.Text = newValue;
        }
    }

    public string NewText
    {
        get { return (string)GetValue(NewTextProperty); }
        set { SetValue(NewTextProperty, value); }
    }

    private TextBlock _customCurrentPagePrefixTextBlock;
    internal TextBlock CustomCurrentPagePrefixTextBlock
    {
        get
        {
            return _customCurrentPagePrefixTextBlock;
        }
        private set
        {
            _customCurrentPagePrefixTextBlock = value;
        }
    }

    public CustomDataPager() 
    {
        this.DefaultStyleKey = typeof(DataPager);
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        CustomCurrentPagePrefixTextBlock = GetTemplateChild("CurrentPagePrefixTextBlock") as TextBlock;
        if (NewText != null)
        {
            CustomCurrentPagePrefixTextBlock.Text = NewText;
        }
    }  

}

现在在此CustomDataPager中设置NewText属性,我们可以获取所需的任何文本,而不是 Page

Now by setting NewText property in this CustomDataPager we can get whatever text we want instead of "Page"

xmlns:local = clr-namespace:Assembly其中包含CustomDataPager

xmlns:local="clr-namespace:Assembly which contains CustomDataPager"

<local:CustomDataPager x:Name="dataPager1" 
                        PageSize="5"
                        AutoEllipsis="True"
                        NumericButtonCount="3"
                        DisplayMode="PreviousNext"
                        IsTotalItemCountFixed="True" NewText="My Text" />

现在它显示我的文本而不​​是页面。

但是其他部分也需要进行自定义,以使其正常工作!

希望这能回答您的问题

Now it displays "My Text" Instead of "Page".
But other parts also need to be customised inorder make this work correctly!!
Hope this answers your question

这篇关于更改DataPager文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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