property changed handle

This commit is contained in:
seraphima 2023-05-08 13:33:35 +02:00
parent 07c4f683ac
commit 42d570b210

View File

@ -45,7 +45,7 @@ namespace Peek.FilePreviewer.Controls
nameof(IsDevFilePreview),
typeof(bool),
typeof(BrowserControl),
new PropertyMetadata(null, new PropertyChangedCallback((d, e) => ((BrowserControl)d).SourcePropertyChanged())));
new PropertyMetadata(null, new PropertyChangedCallback((d, e) => ((BrowserControl)d).OnIsDevFilePreviewChanged())));
public bool IsDevFilePreview
{
@ -57,15 +57,6 @@ namespace Peek.FilePreviewer.Controls
set
{
SetValue(IsDevFilePreviewProperty, value);
if (PreviewBrowser.CoreWebView2 != null)
{
PreviewBrowser.CoreWebView2.Settings.IsScriptEnabled = value;
if (value)
{
PreviewBrowser.CoreWebView2.SetVirtualHostNameToFolderMapping(Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.VirtualHostName, Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.MonacoDirectory, CoreWebView2HostResourceAccessKind.Allow);
}
}
}
}
@ -109,6 +100,18 @@ namespace Peek.FilePreviewer.Controls
Navigate();
}
private void OnIsDevFilePreviewChanged()
{
if (PreviewBrowser.CoreWebView2 != null)
{
PreviewBrowser.CoreWebView2.Settings.IsScriptEnabled = IsDevFilePreview;
if (IsDevFilePreview)
{
PreviewBrowser.CoreWebView2.SetVirtualHostNameToFolderMapping(Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.VirtualHostName, Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.MonacoDirectory, CoreWebView2HostResourceAccessKind.Allow);
}
}
}
private async void PreviewWV2_Loaded(object sender, RoutedEventArgs e)
{
try