Posts

Showing posts from November, 2018

How to dynamically resize WPF tab items to fit available width

Image
Useful StackOverflow link: https://stackoverflow.com/questions/28496809/wpf-flexible-tabcontrol-header Step 1: Create a new WPF application Step 2: Create an example adjustable window with tab items Update the MainWindow.xaml to create a grid with a column section containing the tab items and a grid splitter to adjust the width of the tab item area. MainWindow.xaml We will get on to the step of creating the tab control style in a minute... [code language="xml"] <Window x:Class="TabItemResize.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="450" Width="700...

How to wrap text around another control in WPF

Image
First things first, credit where it's due: the StackOverflow link I eventually found that enabled me to solve this problem: https://stackoverflow.com/questions/3339051/wrapping-text-around-an-image-or-linking-two-textblocks-in-c-sharp-wpf The trick is not use use a TextBlock as conventional wisdom would indicate, but to use a FlowDocument to achieve this kind of layout. For future reference (I am going to need something like this fairly soon), try the following XAML snippet and the resulting WPF app screenshot to demonstrate how to display a button in the top right hand corner with text wrapped around it. In my real-world apps I am using the MVVM pattern with all sorts of bindings and events etc, but this should hopefully enable me to get there: MainWindow.xaml [code language="xml"] <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.mi...