<Window x:Class="Resources.DynamicResource"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Resources" Height="300" Width="300"
>
<Window.Resources>
<ImageBrush x:Key="TileBrush" x:Name="DynamicBrush" TileMode="Tile"
ViewportUnits="Absolute" Viewport="0 0 32 32"
ImageSource="c:\image.jpg"></ImageBrush>
</Window.Resources>
<StackPanel Margin="5">
<Button Background="{DynamicResource TileBrush}" >Button</Button>
<Button Click="cmdChange_Click" >Change the Brush</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 Resources
Public Partial Class DynamicResource
Inherits System.Windows.Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub cmdChange_Click(sender As Object, e As RoutedEventArgs)
Me.Resources("TileBrush") = New SolidColorBrush(Colors.LightBlue)
Dim brush As ImageBrush = DirectCast(Me.Resources("TileBrush"), ImageBrush)
brush.Viewport = New Rect(0, 0, 5, 5)
End Sub
End Class
End Namespace
|