-
September 13th, 2012, 01:59 AM
#1
Data trigger not working with textbox?
Hi,
I am trying/testing out the XAML which were shown in one of the CBT-nuggets for the exam 70-511.
But I am not sure what is wrong. When I select the value 'one' from the combobox, it should print a text to the textbox. But it does not.
Anyone knows?
Thanks in advance!
Code:
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Label}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="pink"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="Text" Value="" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Aqua"/>
</MultiTrigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Label Content="Hover over me" Margin="5,0,392,287" />
<Label Content="Hover over me also" Height="27" HorizontalAlignment="Left" Margin="5,30,0,0" Name="label1" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,63,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
<ComboBox Name="combo" Height="22" HorizontalAlignment="Left" Margin="12,92,0,0" VerticalAlignment="Top" Width="134">
<ComboBoxItem Content="one" />
<ComboBoxItem Content="two" />
<ComboBoxItem Content="three" />
</ComboBox>
<TextBox IsReadOnly="True" DataContext="{Binding ElementName=combo, Path=SelectedItem}" Height="22" HorizontalAlignment="Left" Margin="152,92,0,0" VerticalAlignment="Top" Width="152">
<TextBox.Resources>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="one">
<Setter Property="Text" Value="You have selected one" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Resources>
</TextBox>
</Grid>
</Window>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|