private void FontSizeButton_Click(object sender, RoutedEventArgs e) { var item = sender as MenuFlyoutItem; ViewModel.FontSize = item.FontSize; #if WINDOWS_APP ContentTextBlock.FontWeight = item.FontWeight; // Request an update of the layout since the font size is changed RichTextColumns.ResetOverflowLayout(ContentColumns, null); //ContentColumns.InvalidateMeasure(); #endif }
void Relayout_ContentImages() { foreach (Paragraph para in ContentColumns.RichTextContent.Blocks) { foreach (var inline in para.Inlines) { var container = inline as InlineUIContainer; if (container != null) { var elem = container.Child as FrameworkElement; Size padding = new Size(ContentTextBlock.Padding.Left + ContentTextBlock.Padding.Right, ContentTextBlock.Padding.Top + ContentTextBlock.Padding.Bottom); elem.Width = ContentColumns.ColumnWidth - padding.Width - 1; elem.Height = ContentColumns.ColumnHeight - padding.Height - PictureMargin; } } } RichTextColumns.ResetOverflowLayout(ContentColumns, null); }
private void UpdateContentsView(IEnumerable <LineViewModel> lines) { Uri severBaseUri = new Uri("http://lknovel.lightnovel.cn"); ContentTextBlock.Blocks.Clear(); bool prevLineBreakFlag = false; foreach (var line in lines) { var para = new Paragraph(); para.SetValue(ParagrahViewModelProperty, line); if (line.ContentType == LineContentType.TextContent || line.Content == null) { if (line.HasComments) { para.Inlines.Add(new InlineUIContainer { Child = new SymbolIcon { Symbol = Symbol.Message }, Foreground = (SolidColorBrush)App.Current.Resources["AppAcentBrush"] }); } var run = new Run { Text = line.Content }; para.Inlines.Add(run); para.TextIndent = ContentTextBlock.FontSize * 2; prevLineBreakFlag = true; para.Margin = new Thickness(0, 0, 0, 10); } else { //para.LineHeight = 2; Size padding = new Size(ContentTextBlock.Padding.Left + ContentTextBlock.Padding.Right, ContentTextBlock.Padding.Top + ContentTextBlock.Padding.Bottom); //bitmap.DownloadProgress += //var img = new Image //{ // Source = bitmap, // //MaxWidth = ContentColumns.ColumnWidth - padding.Width - 1, // //Height = ContentColumns.ColumnHeight - padding.Height - PictureMargin, // HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch, // VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch, // Stretch = Stretch.Uniform, //}; //img.DataContext = img; //Flyout.SetAttachedFlyout(img, this.Resources["ImagePreviewFlyout"] as Flyout); //img.Tapped += Illustration_Tapped; //GetLocalImageAsync(new Uri(severBaseUri, line.Content)).ContinueWith(async (task) => //{ // await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=>{ // if (task.IsFaulted || task.Result == null) // { // img.Source = new BitmapImage(new Uri(severBaseUri, line.Content)); // } // else // { // var localUri = task.Result; // img.Source = new BitmapImage(localUri); // } // }); //}); //var illustration = new Border //{ // HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch, // VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch, // Width = ContentColumns.ColumnWidth - padding.Width - 1, // Height = ContentColumns.ColumnHeight - padding.Height - PictureMargin, // Background = null, // BorderBrush = null, // Child = img, //}; var illustration = IllustrationViewTemplate.LoadContent() as Grid; illustration.DataContext = line; illustration.Width = ContentColumns.ColumnWidth - padding.Width - 1; illustration.Height = ContentColumns.ColumnHeight - padding.Height - PictureMargin; var bitmap = (illustration.GetFirstDescendantOfType <Image>().Source as BitmapImage); var pb = illustration.GetFirstDescendantOfType <ProgressBar>(); bitmap.SetValue(BitmapLoadingIndicatorProperty, pb); var inlineImg = new InlineUIContainer { Child = illustration // img }; //inlineImg.FontSize = 620; para.TextAlignment = TextAlignment.Center; if (prevLineBreakFlag) { para.Inlines.Add(new Run { Text = "\n" }); illustration.Margin = new Thickness(0, 5, 0, 0); //img.Margin = new Thickness(0, 5, 0, 0); } else { para.Inlines.Add(new Run { Text = " \n", FontSize = 5 }); } para.Inlines.Add(inlineImg); prevLineBreakFlag = false; } ContentTextBlock.Blocks.Add(para); } var ptr = ContentTextBlock.ContentStart; //ContentColumns.Measure(new Size(ContentScrollViewer.Height, double.PositiveInfinity)); //ContentColumns.Children.Count; RichTextColumns.ResetOverflowLayout(ContentColumns, null); }