2009-12-16 78 views
0

我在Stackoverflow中找到了此answer以刪除Datepicker水印。日期選擇器水印

<Style TargetType="{x:Type toolkit:DatePickerTextBox}"> 
    <Setter Property="Text" Value="Bitte wählen" /> 
</Style> 

是否可以使用vb.net代碼進行上述設置。 謝謝, Rey。

回答

1

我能想到的一種做法是使用資源字典。

創建一個包含該位XAML的資源字典,並將該字典添加到Window Initialized的資源中。這是在WPF中動態更改樣式的好方法。

在Visual Studio中,添加一個新的資源字典,使它看起來像這樣:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" 
        > 
    <Style TargetType="{x:Type toolkit:DatePickerTextBox}"> 
     <Setter Property="Text" Value="Test" /> 
    </Style> 
</ResourceDictionary> 

然後在窗口中添加以下內容添加資源字典將您的應用資源:

Private Sub Window1_Initialized(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Initialized 
    Dim rd As New ResourceDictionary() 
    rd = CType(Application.LoadComponent(New Uri("Dictionary1.xaml", UriKind.Relative)), ResourceDictionary) 
    Application.Current.Resources.MergedDictionaries.Clear() 
    Application.Current.Resources.MergedDictionaries.Add(rd) 
End Sub 

如果您不想使用樣式,那麼似乎有意義的唯一方法是重寫DatePicker的默認實現並實現您自己的。如何做一個很好的說明可以在這裏找到:

http://www.tanguay.info/web/index.php?pg=codeExamples&id=144

+0

我想以編程方式設置文本。我不想使用任何樣式。感謝您的回覆.. – Manohar 2009-12-21 16:35:03

+0

增加了另一個選項,覆蓋他們並使你自己。不理想但肯定可行。 – brendan 2009-12-22 14:39:11