/// <summary> /// Calls method UpdateLayout() on all text elements /// </summary> private void UpdateTextElements() { //News TBlockNewsContent.UpdateLayout(); TBlockNewsTitle.UpdateLayout(); TBlockNewsAuthor.UpdateLayout(); TBlockNewspublishDate.UpdateLayout(); //Message TBlockAdminMessage.UpdateLayout(); TBlockAdminMessageAuthor.UpdateLayout(); TBlockAdminMessageDate.UpdateLayout(); TBlockAdminMessageTitle.UpdateLayout(); }
/// <summary> /// Changes news containers text based on current content. Does nothing with small window size /// </summary> private void NewsTextFormatting() { try { //Set text block elements height based on parent element StackPanel parent = (StackPanel)TBlockNewsContent.Parent; double parentHeight = parent.ActualHeight; if (parentHeight > 100) { //StkPnl --> TxtBlock TBlockNewsTitle.MaxHeight = parentHeight * 0.20; //20% TBlockNewsContent.MaxHeight = parentHeight * 0.60; // 60% //Inside another stackpanel - StkPnl(Parent) --> StkPnl --> TxtBlock TBlockNewspublishDate.MaxHeight = parentHeight * 0.10; //10% TBlockNewsAuthor.MaxHeight = TBlockNewspublishDate.MaxHeight; //10% } //Reset desired font size and proportion TBlockNewsAuthor.FontSize = 30; TBlockNewsContent.FontSize = 40; TBlockNewsTitle.FontSize = 48; TBlockNewspublishDate.FontSize = 30; //Updates all changes made to the text containers UpdateTextElements(); //Incrementally shrink main content until everything fits - Or minimum size reached while (TBlockNewsContent.IsTextTrimmed && TBlockNewsContent.FontSize > 10) { TBlockNewsContent.FontSize--; TBlockNewsContent.UpdateLayout(); } //Incrementally shrink author, date and title until everything fits or minimum limit reached while (TBlockNewsTitle.IsTextTrimmed && TBlockNewsTitle.FontSize > 15) { //Title can't be smaller than Author or Date text element if (TBlockNewsTitle.FontSize - TBlockNewspublishDate.FontSize > 5) { //Title can't be smaller than Author or Date text element if (TBlockNewsTitle.FontSize - TBlockNewspublishDate.FontSize > 5) { TBlockNewsTitle.FontSize--; //Author and Date can't be smaller than 10 pixels - this minimum limits other elements minimum size as well if (TBlockNewspublishDate.FontSize > 10 && TBlockNewsAuthor.FontSize > 10) { TBlockNewspublishDate.FontSize--; TBlockNewsAuthor.FontSize--; } } UpdateTextElements(); } } } catch (Exception error) { DataValidation.SaveError(error.ToString()); } }