Using UWP C# I want to print a report that contains TextBlocks. Depending on the preferences I want to change TextBlock FontSize, FontStyle and FontFamily but DependencyProperty changes FontSize and FontStyle only and FontFamily is not changing.

Naweed Ashraf 1 Reputation point
2024-04-12T03:57:25.7333333+00:00

REPORT PAGE

<Page.DataContext>

<vm:MainViewModel x:Name="mainViewModel" />

</Page.DataContext>

<RichTextBlock>

<Paragraph>

<InlineUIContainer>

<ItemsControl ItemsSource="{Binding PrintArterialVelocities}"

HorizontalAlignment="Stretch"

VerticalAlignment="Stretch"

Margin="0">

<ItemsControl.ItemTemplate>

<DataTemplate>

<Grid>

<Grid.RowDefinitions>

<RowDefinition Height="Auto"/>

</Grid.RowDefinitions>

<Grid.ColumnDefinitions>

<ColumnDefinition Width="5"/>

<ColumnDefinition Width="175"/>

<ColumnDefinition Width="80"/>

<ColumnDefinition Width="200"/>

<ColumnDefinition Width="175"/>

<ColumnDefinition Width="80"/>

</Grid.ColumnDefinitions>

<Border BorderBrush="Black" BorderThickness="0,0,0,1" Grid.Column="1" Grid.ColumnSpan="2"/>

<Border BorderBrush="Black" BorderThickness="0,0,0,1" Grid.Column="4" Grid.ColumnSpan="2"/>

<TextBlock Grid.Column="1" local:VelocitiesText.Text="{Binding ArteryNameA}"/>

<TextBlock Grid.Column="2" local:VelocitiesText.Text="{Binding ArteryVelocityA}"/>

<TextBlock Grid.Column="4" local:VelocitiesText.Text="{Binding ArteryNameB}"/>

<TextBlock Grid.Column="5" local:VelocitiesText.Text="{Binding ArteryVelocityB}"/>

</Grid>

</DataTemplate>

</ItemsControl.ItemTemplate>

</ItemsControl>

</InlineUIContainer>

</Paragraph>

</RichTextBlock>

CALL BACK CLASS

 public class VelocitiesText

 { 
public static string GetText(DependencyObject obj)

 {

     return (string)obj.GetValue(TextBlock.TextProperty);

 }

 public static void SetText(DependencyObject obj, string value)

 {

     obj.SetValue(TextBlock.TextProperty, value);

 }

 public static readonly DependencyProperty TextProperty =

     DependencyProperty.RegisterAttached("Text", typeof(string), typeof(VelocitiesText), new PropertyMetadata(string.Empty, callback));

 public static void callback(DependencyObject d, DependencyPropertyChangedEventArgs e)

 {

     var Txt = (TextBlock)d;

     var InsertString = (string)e.NewValue;            

     Txt.Text = InsertString;

     Txt.FontFamily= TextCalls.SelectedFontFamily;

     Txt.FontSize = double.Parse(TextCalls.SelectedFontSize);

     if (TextCalls.SelectedFontStyle == "Italic")

         Txt.FontStyle = Windows.UI.Text.FontStyle.Italic;          

 }
}

MODEL

 public class ArterialVelocities

 { 
    public int Id { get; set; }

    public string ArteryNameA { get; set; }

    public string ArteryVelocityA { get; set; }

    public string ArteryNameB { get; set; }

   public string ArteryVelocityB { get; set; }
 }
```**VIEWMODEL**

```csharp
public List<ArterialVelocities> PrintArterialVelocities { get; set; }

 public MainViewModel()

 {

 PrintArterialVelocities = new List<ArterialVelocities>();
 PrintArterialVelocities.Clear();

 PrintArterialVelocities.Add(new ArterialVelocities { Id = 1, ArteryNameA = "External Iliac", ArteryVelocityA = "125 cm/s", ArteryNameB = "Common Femoral", ArteryVelocityB = "111 cm/s" });

 PrintArterialVelocities.Add(new ArterialVelocities { Id = 1, ArteryNameA = "Profunda Femoris", ArteryVelocityA = "101 cm/s", ArteryNameB = "Prox: Sup: Femoral", ArteryVelocityB = "95 cm/s" });

 PrintArterialVelocities.Add(new ArterialVelocities { Id = 1, ArteryNameA = "Dist: Sup: Femoral", ArteryVelocityA = "75 cm/s", ArteryNameB = "Popliteal", ArteryVelocityB = "65 cm/s" });
```}
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,268 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.