Custom Page Classes / Programmatic Reuse

Wizard for WPF Forum

Posted 11 years ago by Joe Lozina
Avatar
Hi,
I am trying to use the Programmatic Reuse functionality in the example given and I am wondering how do I get access to controls(ie. text) inside the ItemEntryPage if i would like to change the visability.
I am trying to hide the following textbox

<TextBox Grid.Row="2" Grid.Column="1" Width="100" Margin="0,7,0,0" x:Name="description" Text="{Binding Description}"></TextBox>

TextBox description= (TextBox)this.FindName("description");
description.Visibility = System.Windows.Visibility.Hidden;
I tried this but it returns a null reference

Thanks
Joe

Comments (2)

Posted 11 years ago by Joe Lozina
Avatar
Hi
Ive tried to get the using the following but couldnt get the FrameworkElement/templatedParent using the DataTemplate.FindName(string name, FrameworkElement templatedParent) method. Can you let me know why this isnt working or suggest a solution?

Code I'm trying to use is

DataTemplate dataTemplate = this.ContentTemplate;
TextBox tb = (TextBox)(dataTemplate.FindName(("description", ????)); // ???? how do i get the templatedParent
Also, I noticed that I wasnt able to add the x:key attribute of the DataTemplate in the ItemEntryPage XAML, is there a reason for this?

Thanks
joe
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joe,

I think this article does a good job of explaining what you need to do:
http://blogs.msdn.com/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx

Also, x:Key can only be set in resource dictionaries, not in objects that are applied to setters.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.