I need to access the properties of my object, Cougar, in code behind. I would like to set the value of Drink to Yellow. I’m not sure how to access the Cougar object in code behind. Thanks
<ContentControl x:Name="ccProgress" Grid.Row="0" Grid.ColumnSpan="3" HorizontalContentAlignment="Left" Content="{Binding}">
<ContentControl.ContentTemplate>
<DataTemplate x:Name="dtProgress">
<local:Cougar x:Name="localProgress" Drink="Brown">
</local:Cougar>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
Those two links may help you:
http://pwnedcode.wordpress.com/2009/04/01/find-a-control-in-a-wpfsilverlight-visual-tree-by-name/
http://abubakar-dar.blogspot.com/2010/09/find-control-inside-silverlight.html
http://www.mostlydevelopers.com/mostlydevelopers/blog/post/2009/06/17/Get-Child-Parent-or-Children-Objects-in-Silverlight.aspx
It uses VisualTreeHelper to traverse the tree and find the control by name.
You could also do that using the Loaded event of your Cougar control, if it has one.