我需要根據OpenDialog窗口選擇的文件名來更新childWindow中的textblock。由於我沒有從childWindow運行OpenDialog,因此無法將該值傳遞給ChildWindow內的texblock。我想知道如果有人可以幫助。由於我有這個問題,我想知道是否有可能在ChildWindow中有OpenDialog?感謝您的任何想法!如何在Silverlight中全局更新texblock字符串?
ChildWindow XAML:
<sdk:ChildWindow
x:Class="AddPackages_ChildWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
AutomationProperties.AutomationId="AddPackages_ChildWindow">
<Grid x:Name="AddPackages_ChildWindow_LayoutRoot" AutomationProperties.AutomationId="AddPackages_ChildWindow_LayoutRoot" Style="{StaticResource AVV_GridStyle}">
<TextBlock x:Name="txtUpdate_Package" AutomationProperties.AutomationId="txtUpdate_Package" Text="FileName" /> </Grid>
下面是打開對話框的代碼,並通過選擇文件名:
private void Package_Click(object sender, System.Windows.RoutedEventArgs e)
{
AddPackage_ChildWindow ap = new AddPackage_ChildWindow();
ap.Show();
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "App-V Packages (*.sprj)|*.sprj|App-V Packages (*.sprj)|*.sprj";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = true;
bool? userClickedOK = openFileDialog1.ShowDialog();
if (userClickedOK == true)
{
//passing the file name string
txtUpdate_Package.Text = openFileDialog1.File.Name;
System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream))
{
// Read the first line from the file and write it the textbox.
// txtUpdate_Package.Text = reader.ReadLine();
}
fileStream.Close();
}
}