Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Based on IceForge's answerIceForge's answer I prepared a reusable solution:

xaml style:

<Style x:Key="ComboBoxSelectOverlay" TargetType="TextBlock"> <Setter Property="Grid.ZIndex" Value="10"/> <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/> <Setter Property="Margin" Value="6,4,10,0"/> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> 

example of use:

<Grid> <ComboBox x:Name="cmb" ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}"/> <TextBlock DataContext="{Binding ElementName=cmb,Path=SelectedItem}" Text=" -- Select Team --" Style="{StaticResource ComboBoxSelectOverlay}"/> </Grid> 

Based on IceForge's answer I prepared a reusable solution:

xaml style:

<Style x:Key="ComboBoxSelectOverlay" TargetType="TextBlock"> <Setter Property="Grid.ZIndex" Value="10"/> <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/> <Setter Property="Margin" Value="6,4,10,0"/> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> 

example of use:

<Grid> <ComboBox x:Name="cmb" ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}"/> <TextBlock DataContext="{Binding ElementName=cmb,Path=SelectedItem}" Text=" -- Select Team --" Style="{StaticResource ComboBoxSelectOverlay}"/> </Grid> 

Based on IceForge's answer I prepared a reusable solution:

xaml style:

<Style x:Key="ComboBoxSelectOverlay" TargetType="TextBlock"> <Setter Property="Grid.ZIndex" Value="10"/> <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/> <Setter Property="Margin" Value="6,4,10,0"/> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> 

example of use:

<Grid> <ComboBox x:Name="cmb" ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}"/> <TextBlock DataContext="{Binding ElementName=cmb,Path=SelectedItem}" Text=" -- Select Team --" Style="{StaticResource ComboBoxSelectOverlay}"/> </Grid> 
added 1 character in body
Source Link
Michał Turecki
  • 3.2k
  • 4
  • 40
  • 53

Based on IceForge's answer I prepared a reusable solution:

xaml style:

<Style x:Key="ComboBoxSelectOverlay" TargetType="TextBlock"> <Setter Property="Grid.ZIndex" Value="10"/> <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/> <Setter Property="Margin" Value="6,4,010,0"/> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> 

example of use:

<Grid> <ComboBox x:Name="cmb" ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}"/> <TextBlock DataContext="{Binding ElementName=cmb,Path=SelectedItem}" Text=" -- Select Team --" Style="{StaticResource ComboBoxSelectOverlay}"/> </Grid> 

Based on IceForge's answer I prepared a reusable solution:

xaml style:

<Style x:Key="ComboBoxSelectOverlay" TargetType="TextBlock"> <Setter Property="Grid.ZIndex" Value="10"/> <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/> <Setter Property="Margin" Value="6,4,0,0"/> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> 

example of use:

<Grid> <ComboBox x:Name="cmb" ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}"/> <TextBlock DataContext="{Binding ElementName=cmb,Path=SelectedItem}" Text=" -- Select Team --" Style="{StaticResource ComboBoxSelectOverlay}"/> </Grid> 

Based on IceForge's answer I prepared a reusable solution:

xaml style:

<Style x:Key="ComboBoxSelectOverlay" TargetType="TextBlock"> <Setter Property="Grid.ZIndex" Value="10"/> <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/> <Setter Property="Margin" Value="6,4,10,0"/> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> 

example of use:

<Grid> <ComboBox x:Name="cmb" ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}"/> <TextBlock DataContext="{Binding ElementName=cmb,Path=SelectedItem}" Text=" -- Select Team --" Style="{StaticResource ComboBoxSelectOverlay}"/> </Grid> 
Source Link
Michał Turecki
  • 3.2k
  • 4
  • 40
  • 53

Based on IceForge's answer I prepared a reusable solution:

xaml style:

<Style x:Key="ComboBoxSelectOverlay" TargetType="TextBlock"> <Setter Property="Grid.ZIndex" Value="10"/> <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/> <Setter Property="Margin" Value="6,4,0,0"/> <Setter Property="IsHitTestVisible" Value="False"/> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> 

example of use:

<Grid> <ComboBox x:Name="cmb" ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}"/> <TextBlock DataContext="{Binding ElementName=cmb,Path=SelectedItem}" Text=" -- Select Team --" Style="{StaticResource ComboBoxSelectOverlay}"/> </Grid>