Search code examples
silverlight-4.0expression-blend-4

Changing TextBlock Foreground using VSM when mouse over?


anyone know how can i use VSM chang a textblock text color from "Red" to "Blue" ?do textblock have temeplate like Button,TextBox... and so on ? thanks for you help and looking forward to your reply...


Solution

  • you can use Textbox and set color background on mouse over

    <TextBox TextWrapping="Wrap" Background="#FFBA2C2C" Height="20">
            <TextBox.Template>
                <ControlTemplate>
                    <StackPanel Orientation="Horizontal">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimation  To="Red" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="textBlock" d:IsOptimized="True" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <TextBlock x:Name="textBlock" Text="Click Me"/>
                        </StackPanel>
                </ControlTemplate>
            </TextBox.Template>
        </TextBox>