私の MainWindow には、FlowDocumentScrollViewer
そのプロパティDocument
をMainViewModelFlowDocument
の aにバインドしています。
このドキュメントは、リモート コンピューター上の外部 xaml ファイル ストアから読み込まれます。現在、このドキュメントを で適切に読み込んXamlReader.Load(xamlfile)
で表示することができFlowDocumentScrollViewer
ます。ここまでは順調ですね。
このドキュメントにハイパーリンクを追加しようとすると、問題が発生します。RequestNavigate
イベントを処理するにはx:Class
. MainWindow
イベントはコード ビハインドでハンドルされるため、当分の間、このクラスは my である必要があります。明らかに、外部ドキュメントを追加すると、解析時にx:Class="Ugrader.MainWindow"
素敵な結果が得られます。'System.Windows.Markup.XamlParseException'
これを解決する方法はありますか?
これが私のコードの一部です
MainWindow.xaml
<Window x:Class="Ugrader.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Geco3-Upgrading version"
WindowStyle="none" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
Height="400" Width="700"
DataContext="{Binding Main,Source={StaticResource Locator}}">
<FlowDocumentScrollViewer Grid.Column="1" Background="{x:Null}" VerticalScrollBarVisibility="Hidden"
Document="{Binding WhatsNewDoc}"/>
</Window>
MainViewModel.cs
namespace Ugrader.ViewModel
{
public class MainViewModel : ViewModelBase
{
#region Constructor
public MainViewModel()
{
try
{
FileStream xamlFile = new FileStream(updateLocation + "whatsnew.xaml", FileMode.Open, FileAccess.Read);
FlowDocument current = System.Windows.Markup.XamlReader.Load(xamlFile) as FlowDocument;
WhatsNewDoc = current;
}
catch (Exception)
{
}
}
#endregion
#region Properties
private FlowDocument _watsNewDoc = new FlowDocument();
public FlowDocument WhatsNewDoc
{
get
{
return _watsNewDoc;
}
set
{
if(_watsNewDoc != value)
{
_watsNewDoc = value;
RaisePropertyChanged("WhatsNewDoc");
}
}
}
#endregion
}
}
外部 FlowDocument
<FlowDocument x:Class="Ugrader.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ColumnWidth="400" FontSize="12" FontFamily="Century Gothic" Foreground="LightGray">
<Paragraph>
<Italic>
For additionnal information, please watch this
<Hyperlink TextDecorations="{x:Null}" RequestNavigate="Hyperlink_Clicked" NavigateUri="path_to_the_file" >video</Hyperlink>
</Italic>
</Paragraph>
</FlowDocument>
ところで、この解析例外を処理する方法はありますか (不正な外部ファイルの場合)。この try/catch ブロックでもプログラムが停止するからです。
よろしくお願いします。
バスティアン。