You can show the Watermark by adding Load event
for your ComboBox
and adding its code like below when the selection is null:
private void myCom_Loaded(object sender, RoutedEventArgs e)
{
myCom.SelectedIndex = -1;
}
I tested your code in three ways:
One: I did a test project and reproduced your error with setting SelectedItem="{Binding SelectedCourse, Mode=TwoWay}"
for the ComboBox
, but when I deleted SelectedItem="{Binding SelectedCourse, Mode=TwoWay}"
and not using SelectedValue
for the ComboBox like below, the issue still existed.
<ComboBox VerticalAlignment="Center"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding ActiveCourses}"
>
Two: Then I tried to add SelectedValue
and not use SelectedItem="{Binding SelectedCourse, Mode=TwoWay}"
like below, the is also existed.
<ComboBox VerticalAlignment="Center"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding ActiveCourses}"
SelectedValue="Model1"
SelectedValuePath="Model"
>
Three: Finally I tried to use binding to SelectedValue
, it can show Watermark but with binding error
, like below oicture shown:
It is inferred from the test results that the cause of this problem should be that you created the DataTemplate for the ComboBox.If I misunderstand your question, please point out.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.