WPF - Auto Size All Text

I am trying to automatically change all elements in my application to the parent element. And it goes well with the use of grids, margin and auto size. The problem is that the text size does not change and becomes very small inside a large element. I tried using the viewbox with buttons that work well:

<Button x:Name="button_1"> <Viewbox> <TextBlock Text="Button1"></TextBlock> </Viewbox> </Button> 

But I can't get this to work with the title in TreeviewItem. How can I change the font size of all my text elements in an application? Any solutions for this are very convenient. No need to enable the use of viewbox elements.

Edit: Perhaps I have formulated my question somewhat obscure. My problem is to authorize the text inside the title in the TreeViewItem.

 <TreeView x:Name="tree1" Margin="0"> <TreeViewItem x:Name="item1" Header="Item1"> //This header needs to autosize ... </TreeViewItem> </TreeView> 

Solution: Equivalent to the answer mathieu provided.

 <TreeView x:Name="tree1" Margin="0"> <TreeViewItem x:Name="item1"> <TreeViewItem.Header> <Viewbox> <TextBlock>Item1</TextBlock> </Viewbox> </TreeViewItem.Header> </TreeViewItem> </TreeView> 
+4
source share
2 answers

Declare your title as follows:

 <TreeView x:Name="tree1" Margin="0"> <TreeViewItem x:Name="item1"> <TreeViewItem.Header> <Viewbox> <TextBlock TextWrapping="Wrap" Text="Header" /> </Viewbox> </TreeViewItem.Header> </TreeViewItem> </TreeView> 
+1
source

Go through this code:

 String text = "Your Text Goes here"; Typeface objTypeFace = new Typeface("Helvetica"); FormattedText objft = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, objTypeFace , 20, Brushes.Red); Size textSize = new Size(objft.Width, objft.Height); 

OR

 <Button x:Name="button_1"> <Viewbox> <TextBlock TextWrapping="Wrap" Text="Button1"></TextBlock> </Viewbox> </Button> 
0
source

All Articles