Occurs when the value of the
SizeMode property changes.
Syntax
XAML Attributes Usage | |
---|
<object SizeModeChanged=EventHandler<ExceptionRoutedEventArgs>/> ... |
Routed Event Information | |
---|
Identifier field | SizeModeChangedEvent |
Routing strategy | Bubbling |
Delegate | EventHandler<(Of <(TEventArgs>)>) |
XAML Attributes Usage | |
---|
<object SizeModeChanged=EventHandler<ExceptionRoutedEventArgs>/> ... |
Routed Event Information | |
---|
Identifier field | SizeModeChangedEvent |
Routing strategy | Bubbling |
Delegate | EventHandler<(Of <(TEventArgs>)>) |
Example
This example uses the SizeModeChanged event to show how the SizeMode has changed.
Visual Basic | Copy Code |
---|
Private Sub viewer_SizeModeChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of PaintSizeMode))
Dim viewer As BitmapSourceViewer = CType(IIf(TypeOf sender Is BitmapSourceViewer, sender, Nothing), BitmapSourceViewer)
Dim s As String = String.Format("SizeModeChanged Event: {0}", viewer.SizeMode.ToString())
MessageBox.Show(s)
End Sub
Public Sub BitmapSourceViewerElement_SizeModeChanged(ByVal viewer As BitmapSourceViewerElement)
AddHandler viewer.SizeModeChanged, AddressOf viewer_SizeModeChanged
Select Case viewer.SizeMode
Case PaintSizeMode.Fit
viewer.SizeMode = PaintSizeMode.FitAlways
Case PaintSizeMode.FitAlways
viewer.SizeMode = PaintSizeMode.FitWidth
Case PaintSizeMode.FitWidth
viewer.SizeMode = PaintSizeMode.Normal
Case PaintSizeMode.Normal
viewer.SizeMode = PaintSizeMode.Stretch
Case PaintSizeMode.Stretch
viewer.SizeMode = PaintSizeMode.Fit
End Select
RemoveHandler viewer.SizeModeChanged, AddressOf viewer_SizeModeChanged
End Sub |
C# | Copy Code |
---|
private void viewer_SizeModeChanged(object sender, EventArgs e) { BitmapSourceViewerElement viewer = sender as BitmapSourceViewerElement; string s = string.Format("SizeModeChanged Event: {0}", viewer.SizeMode.ToString()); MessageBox.Show(s); } public void BitmapSourceViewerElement_SizeModeChanged(BitmapSourceViewerElement viewer) { viewer.SizeModeChanged += new RoutedPropertyChangedEventHandler<PaintSizeMode>(viewer_SizeModeChanged); switch(viewer.SizeMode) { case PaintSizeMode.Fit: viewer.SizeMode = PaintSizeMode.FitAlways; break; case PaintSizeMode.FitAlways: viewer.SizeMode = PaintSizeMode.FitWidth; break; case PaintSizeMode.FitWidth: viewer.SizeMode = PaintSizeMode.Normal; break; case PaintSizeMode.Normal: viewer.SizeMode = PaintSizeMode.Stretch; break; case PaintSizeMode.Stretch: viewer.SizeMode = PaintSizeMode.Fit; break; } viewer.SizeModeChanged -= new RoutedPropertyChangedEventHandler<PaintSizeMode>(viewer_SizeModeChanged); } |
XAML | Copy Code |
---|
<Window x:Class="WPFSamples.BitmapSourceViewerElement" Height="600" Width="800" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"> <DockPanel> <Leadtools_Windows_Controls:BitmapSourceViewerElement Name="theImage" Source="file:///C:\Program Files\LEAD Technologies\LEADTOOLS 16\Images\slave.jpg" DockPanel.Dock="Bottom" HorizontalAlignment="Center" VerticalAlignment="Bottom" MouseDown="theImage_MouseClick" SizeModeChanged="viewer_SizeModeChanged"></Leadtools_Windows_Controls:BitmapSourceViewerElement> </DockPanel> <Window.Title> "Size mode =Normal, double click to change" </Window.Title> </Window> |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family
See Also