OpenDialog Windowで選択されているファイル名に基づいて、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();
}
}