0
這可能聽起來像一個奇怪的請求,我不確定它是否真的有可能,但是我有一個Silverlight DataPager控件,它表示「第1頁的X」,我想更改「Page」文本說些不同的話。更改數據更新文本
可以這樣做嗎?
這可能聽起來像一個奇怪的請求,我不確定它是否真的有可能,但是我有一個Silverlight DataPager控件,它表示「第1頁的X」,我想更改「Page」文本說些不同的話。更改數據更新文本
可以這樣做嗎?
在DataPager樣式中,默認情況下,其名稱爲CurrentPagePrefixTextBlock,其值爲「Page」。 您可以參考http://msdn.microsoft.com/en-us/library/dd894495(v=vs.95).aspx瞭解更多信息。
其中一個解決方案是延長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財產,我們想要的任何文本,而不是「頁面」
的xmlns:地方= 「CLR的命名空間:大會包含CustomDataPager」
<local:CustomDataPager x:Name="dataPager1"
PageSize="5"
AutoEllipsis="True"
NumericButtonCount="3"
DisplayMode="PreviousNext"
IsTotalItemCountFixed="True" NewText="My Text" />
現在它顯示「我的文本」而不是「頁面」。
但其他部分也需要定製,以使其正確工作!
希望這回答你的問題