을 나는 FlowDocumentScrollViewer
내 MainViewModel에 FlowDocument
에 해당 속성 Document
바인딩이있다.FlowDocument 및 XamlReader X : 클래스 내 MainWindow를에서
이 문서는 원격 컴퓨터의 외부 xaml 파일 저장소에서로드됩니다. 현재 XamlReader.Load(xamlfile)
을 통해이 문서를 올바르게로드하고 FlowDocumentScrollViewer
에 표시 할 수 있습니다. 여태까지는 그런대로 잘됐다.
이 문서에서 하이퍼 링크를 추가하려고하면이 문제가 발생합니다. RequestNavigate
이벤트를 처리하려면 x:Class
이 필요합니다. 이벤트가 코드 숨김에서 처리되기 때문에 당분간이 클래스는 내 MainWindow
일 필요가 있습니다. 분명히 내 외부 문서에 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 블록에서도 내 프로그램을 중지하기 때문에이 예외를 파싱합니다 (잘못된 외부 파일의 경우). 사전에
감사를,
Bastien.