<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WpfApplication1" Height="231" Width="544" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key ="TiltStyle" TargetType = "{x:Type Button}">
<Setter Property = "RenderTransform">
<Setter.Value>
<RotateTransform Angle = "30"/>
</Setter.Value>
</Setter>
</Style>
<Style x:Key ="GreenStyle" TargetType = "{x:Type Button}">
<Setter Property = "Background" Value ="Green"/>
<Setter Property = "Foreground" Value ="Yellow"/>
<Setter Property ="FontSize" Value ="15" />
</Style>
<Style x:Key ="MouseOverStyle" BasedOn ="{StaticResource GreenStyle}" TargetType = "{x:Type Button}">
<Style.Triggers>
<Trigger Property ="IsMouseOver" Value ="True">
<Setter Property ="FontSize" Value ="20" />
<Setter Property ="Foreground" Value ="Black" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<ListBox Name ="lstStyles" Height ="60" Background = "Yellow"
SelectionChanged ="comboStyles_Changed" />
<Button Name="btnMouseOverStyle" Grid.Column="1"
Height="40" Width="100" Click ="btnMouseOverStyle_Click">My Button</Button>
</StackPanel>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes
Namespace WpfApplication1
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
lstStyles.Items.Add("TiltStyle")
lstStyles.Items.Add("GreenStyle")
lstStyles.Items.Add("MouseOverStyle")
End Sub
Protected Sub comboStyles_Changed(sender As Object, args As RoutedEventArgs)
Dim currStyle As System.Windows.Style = DirectCast(FindResource(lstStyles.SelectedValue), System.Windows.Style)
Me.btnMouseOverStyle.Style = currStyle
End Sub
Protected Sub btnMouseOverStyle_Click(sender As Object, args As RoutedEventArgs)
MessageBox.Show("Clicked")
End Sub
End Class
End Namespace
|