2

i want a default text on my combobox as i have binded my combo box to certain list of items...here is my code of xaml file.

<ComboBox x:Name="ProjectComboBox" Text="{Binding ProjectNameBinding}" ItemsSource="{Binding projectList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ProjectNameBindingClass, Mode=OneWayToSource}" Width="130" Background="White" BorderThickness="1" FontFamily="/TimeSheet;component/Resources/#Open Sans" FontSize="12" Canvas.Right="159" Canvas.Top="8" Height="47"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding _name}" TextWrapping="Wrap"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> 
2
  • it helps, if you ask a concrete question on the end of the text. it also if you describe what you already tried to achieve that - so you show own efforts instead of blindly letting others work for you. ;-) Commented Mar 21, 2014 at 12:43
  • Possible duplicate stackoverflow.com/questions/1426050/… Commented Mar 21, 2014 at 12:44

4 Answers 4

2

Have you tried Text Property

<ComboBox x:Name="ProjectComboBox" IsEditable=True Text="{Binding ProjectNameBinding}" ....../> 

or

You can use SelectedIndex Property and set it to 0(SelectedIndex=0) which displays first item in Source given.

or

you can do like this as in the link How to display default text "--Select Team --" in combo box on pageload in WPF?

Sign up to request clarification or add additional context in comments.

7 Comments

xmlns:Converters="clr-namespace:MyProject.Resources.Converters" , this line in xaml gives an error,what to write exactly and is there anything to import,i am missing it???????
i was not embedding the converter properly in my project folder
you also suggested a very nice way but actually i didnt wanted that way...i have posted my code down check it out
can you help me out on a question i have posted,i am not able to get alpha icon transparency,check out my question if you have any solution
Yeah i saw.Check the Converters class namespace.Is it MyProject.Resources.Converters..?
|
1

I achieved it atlast by taking a new textblock and applying a trigger on it,and using the IsNullConverter class it helped

<TextBlock Text="Select Project" IsHitTestVisible="False" FontFamily="/TimeSheet;component/Resources/#Open Sans" FontSize="14" Canvas.Right="191" Canvas.Top="22"> <TextBlock.Resources> <Converters:IsNullConverter x:Key="isNullConverter"/> </TextBlock.Resources> <TextBlock.Style> <Style TargetType="TextBlock"> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=ProjectComboBox,Path=SelectedItem,Converter={StaticResource isNullConverter}}" Value="False"> <Setter Property="Visibility" Value="Hidden"/> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> 

Comments

0

Try:

DefaultText="Not Specified" 

2 Comments

I think there is no property like "DefaultText" in combobox and also in text block
I cannot change the C# code as i have my xml file binded to it i.e to the list of combobox ,can we have any solution using XAML code only
0

Try this in page load or form load

 comboBox.SelectedItem = null; comboBox.Text = "---select an item---"; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.