Yeah you can bind to a public property but not to a private property or any kind of variable/field. Here's an example:
Code:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Name="Window1"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
>
<Grid>
<TextBox Name="TextBox1" Text="{Binding Path=MyText}" Height="30" Width="100" />
</Grid>
</Window>
and here is the entire code behind file:
vb.net Code:
Class Window1
Private _MyText As String = "test"
Public Property MyText() As String
Get
Return _MyText
End Get
Set(ByVal value As String)
_MyText = value
End Set
End Property
End Class
Note the DataContext line in the XAML (part of the Window attributes at the top) - you dont need to do this if you set your binding in code but if you just do it like this then it doesnt seem to work without that line. I asked about it here and the only solution I got really was to just set binding sources in code and so thats what I do:
http://social.microsoft.com/Forums/e...5-510b73d414ed