Mega Code Archive

 
Categories / VB.Net Tutorial / WPF
 

Load resource from Window Resources

<Window x: Class="ControlStyles.Window1"   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   Title="ControlStyles" Height="300" Width="300">   <Window.Resources>     <Style x:Key="BigLettersStyle">       <Setter Property="Control.FontSize" Value="20" />       <Setter Property="Control.FontWeight" Value="Bold" />       <Setter Property="Control.BorderThickness" Value="2" />     </Style>          <Style x:Key="SmallLettersStyle">       <Setter Property="Control.FontSize" Value="10" />       <Setter Property="Control.FontWeight" Value="Normal" />       <Setter Property="Control.BorderThickness" Value="1" />     </Style>   </Window.Resources>   <Grid>     <Button Click="MyClickEvent"       Style="{StaticResource SmallLettersStyle}"       VerticalAlignment="Top"       HorizontalAlignment="Left"       Grid.Column="0"       Grid.ColumnSpan="1"       Grid.Row="0"       Grid.RowSpan="1"       Margin="43"       Width="75"       Height="23"       Name="btnGo">Go</Button>   </Grid> </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 ControlStyles   Public Partial Class Window1     Inherits System.Windows.Window     Public Sub New()       InitializeComponent()     End Sub     Private Sub MyClickEvent(sender As Object, e As RoutedEventArgs)       btnGo.Style = DirectCast(FindResource("BigLettersStyle"), Style)     End Sub   End Class End Namespace