views:

416

answers:

1

I found this answer in Stackoverflow for Removing Datepicker Watermark.

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

is it possible to set above using vb.net code. Thank you, Rey.

+1  A: 

The one way I can think of to do this is using a resource dictionary.

Create a resource dictionary with that bit of XAML in it and add the dictionary to your resources on Window Initialized. This is a nice way to change styles dynamically in WPF.

In Visual Studio, add a new Resource Dictionary and make it look like this:

<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>

Then in your window add the following to add the resource dictionary to your apps resources:

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

If you don't want to use styles the only thing that seems to make sense then is to override the default implementation of the DatePicker and implement your own. A good description of how to do that can be found here:

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

brendan
I want to programmatically set the text. i dont want to use any styles. Thanks for the reply..
Rey
Added another option, override their and make your own. Not ideal but certainly doable.
brendan