You can also derive from TextBlock (instead of userControl) like this:
<TextBlock x:Class="WpfGridRowHeightStackOverflowQuestion.MyRotatedTextBlock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90"/>
</TextBlock.LayoutTransform>
</TextBlock>
Then just use the Text property from the TextBlock like this:
<myNamespace:MyRotatedTextBlock Grid.Row="1" Grid.Column="0" Text="MyHeader2"></myNamespace:MyRotatedTextBlock>
EDIT
This way it works as a UserControl as well (because the elementname of the binding is specified explicitly to the user control's name):
<UserControl x:Class="WpfGridRowHeightStackOverflowQuestion.MyRotatedTextBlock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Name="CustomRotatedTextBlock">
<TextBlock Text="{Binding ElementName=CustomRotatedTextBlock,Path=MyText}" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90"/>
</TextBlock.LayoutTransform>
</TextBlock>
</UserControl>
Then i code behind use Change Notification by INotifyPropertyChanged (which WPF relies heavy upon ;)
public partial class MyRotatedTextBlock : UserControl, INotifyPropertyChanged
{
public MyRotatedTextBlock()
{
InitializeComponent();
}
private String _myText;
public String MyText
{
get { return _myText; }
set {
_myText = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("MyText"));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}