I have a Usercontrol in a UserControl library (separate assembly). I have in my XAML markup like this:
<UserControl x:Class="CenterTextTemplate.CenterTextTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="Test"
Height="Auto"
Width="Auto">
<Grid>
<!--<TextBlock Name="TextField" Text="{Binding Text}"></TextBlock> -->
<Viewbox VerticalAlignment="Center"
HorizontalAlignment="Center">
<TextBlock Name="TextField"
Text="{Binding Text, ElementName=Test}"
Foreground="Red" FontSize="50">
</TextBlock>
</Viewbox>
</Grid>
In my .cs file i have a property:
public string Text { get { return "test"; } }
When I load the usercontrol I see no “test” text… is there something I’m missing? Tried to not give a Name to the usercontrol but that didnt work either…
EDIT:
In this setup I get this error:
Error 1 The type name ‘CenterTextTemplate’ does not exist in the type
‘CenterTextTemplate.CenterTextTemplate’ C:\Documents and
Settings\Brian Hvarregaard\My Documents\Visual Studio
2008\Projects\GreenWeb
Templates\CenterTextTemplate\CenterTextTemplate.xaml 4 37 CenterTextTemplate
You need to use a dependency property to bind to a property. See this link as well as the msdn page for
DependencyProperty.