如下是子窗體的UI:html
<Window x:Class="Automatically.View" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="View" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" Icon="/Automatically;component/Images/schedule.ico" > <Grid> <DockPanel> <Image Name="Icon" Width="35" Height="35" DockPanel.Dock="Left"/> <TextBlock Name="tbk_Files"></TextBlock> </DockPanel> </Grid> </Window>
子窗體的代碼:多線程
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace Automatically { /// <summary> /// Interaction logic for View.xaml /// </summary> public partial class View : Window { private object lbi; public View(object lbi) { InitializeComponent(); // TODO: Complete member initialization this.lbi = lbi; this.Dispatcher.Invoke(new Action(delegate { DockPanel dp = lbi as DockPanel; foreach (UIElement ele in dp.Children) { if (ele is Image) { Image img = ele as Image; Icon.Source = img.Source; } if (ele is TextBlock) { TextBlock tbk = ele as TextBlock; foreach (var t in tbk.Inlines) { if (t is Run) { Run r = t as Run; tbk_Files.Inlines.Add(new Run(r.Text)); } if (t is LineBreak) { LineBreak l = t as LineBreak; tbk_Files.Inlines.Add(new LineBreak()); } } } } })); } } }
到此就完結了,但願給各位初學WPF的一些提示.ide
須要源碼的小朋友能夠留言啦!!!this