===========子窗口========ChildWindowShow==========
<controls:ChildWindow x:Class="SilverlightSocket.ChildWindowShow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Width="400" Height="300" Title="ChildWindowShow">
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image x:Name="imgContent" Grid.Row="0" Grid.Column="0"></Image>'定义一个图片
<Button x:Name="CancelButton" Content="取消" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1"/>
<Button x:Name="OKButton" Content="确定" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1"/>
</Grid>
</controls:ChildWindow>
===========XAML===========
<UserControl x:Class="SilverlightSocket.openwindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<StackPanel x:Name="LayoutRoot" Orientation="Horizontal">
<StackPanel.Background>
<ImageBrush ImageSource="/Images/win7-12.jpg" Stretch="UniformToFill"/>
</StackPanel.Background>
</StackPanel>
</UserControl>
=================VB==================
Imports System.Windows.Media.Imaging
Partial Public Class openwindow
Inherits UserControl
Public Sub New()
InitializeComponent()
BuildElement()
End Sub
Public Sub BuildElement()
For i = 1 To 5
Dim uri As New Uri(String.Format("Images/win7-{0}.jpg", i), UriKind.RelativeOrAbsolute) ''''定义URI对象
Dim btn As New Button
Dim img As New Image()
img.Width = 150
img.Height = 150
img.Stretch = Stretch.Fill
img.Source = New BitmapImage(uri)
btn.Width = 150
btn.Height = 150
btn.Margin = New Thickness(5)
btn.Content = img
'AddHandler btn.Click, (AddressOf btn_click(btn, Button))
' btn.Click += New Button
'ck1.Click+=new System.EventHandler(MyClick
' New EventHandler(Of wcfsilverlight.ServiceReference1.GetLogCompletedEventArgs)
AddHandler btn.Click, New RoutedEventHandler(AddressOf btn_click)
LayoutRoot.Children.Add(btn)
Next
End Sub
Public Sub btn_click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim btn As Button = sender
Dim cw As New ChildWindowShow
Dim img As Image = btn.Content
cw.imgContent.Source = img.Source
cw.Show()
End Sub
End Class