Acces to a button in a DataTemplate<P>Hello everybody,</P> <P>&nbsp;</P> <P>In my application, I've got this XAML code:</P><FONT color=#0000ff size=2> <P>&lt;</FONT><FONT color=#800000 size=2>Page.Resources</FONT><FONT color=#0000ff size=2>&gt;</FONT><FONT color=#0000ff size=2></P> <P>&lt;</FONT><FONT color=#800000 size=2>SharepointListItemsViewer:NodeTemplateSelector</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>x:Key</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>nodeTemplateSelector</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Page.Resources</FONT><FONT color=#0000ff size=2>&gt;</FONT></P> <P><FONT color=#0000ff size=2>&nbsp;</P></FONT><FONT color=#0000ff size=2> <P>&lt;</FONT><FONT color=#800000 size=2>Graph:Graph</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theGraph</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>NodesBindingPath</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>ChildNodes</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </P> <P></FONT><FONT color=#ff0000 size=2>CoefficientOfDampening</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.7</FONT><FONT size=2>"</P></FONT><FONT color=#0000ff size=2> <P></FONT><FONT color=#ff0000 size=2>FrameRate</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.5</FONT><FONT size=2>"</P></FONT><FONT color=#0000ff size=2> <P></FONT><FONT color=#ff0000 size=2>NodeTemplateSelector</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{StaticResource nodeTemplateSelector}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Graph:Graph.Resources</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Style</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetType</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{x:Type Button}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Template</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter.Value</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ControlTemplate</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetType</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{x:Type Button}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Border</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theBorder</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>BorderBrush</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Gray</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>BorderThickness</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>2</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>CornerRadius</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>10</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Padding</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>5</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Background</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{TemplateBinding Background}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ContentPresenter</FONT><FONT color=#0000ff size=2>/&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Border</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ControlTemplate.Triggers</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>IsMouseOver</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetName</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theBorder</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>BorderBrush</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>#333333</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>/&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>IsPressed</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetName</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theBorder</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Background</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>#CCCCCC</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>/&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>ControlTemplate.Triggers</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>ControlTemplate</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Setter.Value</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Style</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>x:Key</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>nodeTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Background</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>BurlyWood</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>CommandParameter</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding }</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Click</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>DisplayDetails</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>btnodeTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</FONT><FONT color=#0000ff size=2></P> <P>&lt;</FONT><FONT color=#800000 size=2>StackPanel</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Orientation</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Vertical</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Image</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Source</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.ImageUrl, Mode=OneWay, Converter={StaticResource ImageConverter}}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>ItemDisplayedImage</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Width</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>TextBlock</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Text</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.Name}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>FontSize</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>11</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>StackPanel</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>x:Key</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>PersonTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Background</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>BurlyWood</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>CommandParameter</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding }</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Click</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>DisplayDetails</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>btPersonTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Grid</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Grid.ColumnDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ColumnDefinition</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ColumnDefinition</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Grid.ColumnDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Grid.RowDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>RowDefinition</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.1*</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>RowDefinition</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.9*</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Grid.RowDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Image</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Source</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.ImageUrl, Mode=OneWay, Converter={StaticResource ImageConverter}}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>ItemDisplayedImage</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Width</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Row</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.ColumnSpan</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>2</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>WindowsFormsHost</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>HostPresenceControl</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Row</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>1</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Column</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Margin</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0,0,5,0</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Presence:Persona</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>UserPresence</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>WindowsFormsHost</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>TextBlock</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Text</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.Name}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Row</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>1</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Column</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>1</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>FontSize</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>11</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Grid</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Graph:Graph.Resources</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Graph:Graph</FONT><FONT color=#0000ff size=2>&gt;</P></FONT> <P>And here is the DataTemplateSelector class associated to this XAML code:</P><FONT color=#0000ff size=2> <P>internal</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>class</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>NodeTemplateSelector</FONT><FONT size=2> : </FONT><FONT color=#008080 size=2>DataTemplateSelector</P></FONT><FONT size=2> <P>{</P> <P></FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>override</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2> SelectTemplate(</FONT><FONT color=#0000ff size=2>object</FONT><FONT size=2> item, </FONT><FONT color=#008080 size=2>DependencyObject</FONT><FONT size=2> container)</P> <P>{</P> <P></FONT><FONT color=#008080 size=2>Node</FONT><FONT size=2>&lt;</FONT><FONT color=#008080 size=2>Item</FONT><FONT size=2>&gt; node = item </FONT><FONT color=#0000ff size=2>as</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>Node</FONT><FONT size=2>&lt;</FONT><FONT color=#008080 size=2>Item</FONT><FONT size=2>&gt;;</P> <P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (node != </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>)</P> <P>{</P> <P></FONT><FONT color=#008000 size=2>// Select the correct NodeTemplate according to the type of the item</P></FONT><FONT size=2> <P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (node.Item.Type == </FONT><FONT color=#008080 size=2>ItemType</FONT><FONT size=2>.Person)</P> <P>{</P> <P></FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2> Template = ((</FONT><FONT color=#008080 size=2>FrameworkElement</FONT><FONT size=2>)container).FindResource(</FONT><FONT color=#800000 size=2>"PersonTemplate"</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>as</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2>;</FONT><FONT color=#008000 size=2></P></FONT><FONT size=2> <P></FONT><FONT color=#008080 size=2>Button</FONT><FONT size=2> btn = Template.FindName(</FONT><FONT color=#800000 size=2>"btPersonTemplate"</FONT><FONT size=2>, ???</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>as</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>Button</FONT><FONT size=2>;</P> <P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> (</FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2>)((</FONT><FONT color=#008080 size=2>FrameworkElement</FONT><FONT size=2>)container).FindResource(</FONT><FONT color=#800000 size=2>"PersonTemplate"</FONT><FONT size=2>);</P> <P>}</P> <P></FONT> <P><FONT color=#008000 size=2></P></FONT><FONT size=2></FONT><FONT color=#0000ff size=2>else <P></P></FONT><FONT size=2> <P>{</P> <P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> (</FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2>)((</FONT><FONT color=#008080 size=2>FrameworkElement</FONT><FONT size=2>)container).FindResource(</FONT><FONT color=#800000 size=2>"nodeTemplate"</FONT><FONT size=2>);</P> <P>}</P> <P>}</P> <P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>;</P> <P>}</P> <P>}</P></FONT> <P>I want to ba able to access to the Button which is in my DataTemplate to do some binding on the WindowsFormsHost's Child (accessible using VisualTreeHelper class).</P> <P>But I don't know what I need to use here as a second parameter of the FindName mehod:</P> <P><FONT size=2><FONT color=#008080>Button</FONT> btn = Template.FindName(<FONT color=#800000>"btPersonTemplate"</FONT>, ???) <FONT color=#0000ff>as</FONT> <FONT color=#008080>Button</FONT>;</FONT></P> <P>&nbsp;</P> <P>Anyone have an idea ? Or maybe another/better idea ?</P> <P>&nbsp;</P> <P>&nbsp;</P> <P>Thanks !</P> <P>&nbsp;</P> <P>Thomas</P>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Ze06a1d2b-f458-4e9b-8c71-04df332d5299http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#e06a1d2b-f458-4e9b-8c71-04df332d5299http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#e06a1d2b-f458-4e9b-8c71-04df332d5299Thomas LEBRUNhttp://social.msdn.microsoft.com/Profile/en-US/?user=Thomas%20LEBRUNAcces to a button in a DataTemplate<P>Hello everybody,</P> <P>&nbsp;</P> <P>In my application, I've got this XAML code:</P><FONT color=#0000ff size=2> <P>&lt;</FONT><FONT color=#800000 size=2>Page.Resources</FONT><FONT color=#0000ff size=2>&gt;</FONT><FONT color=#0000ff size=2></P> <P>&lt;</FONT><FONT color=#800000 size=2>SharepointListItemsViewer:NodeTemplateSelector</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>x:Key</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>nodeTemplateSelector</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Page.Resources</FONT><FONT color=#0000ff size=2>&gt;</FONT></P> <P><FONT color=#0000ff size=2>&nbsp;</P></FONT><FONT color=#0000ff size=2> <P>&lt;</FONT><FONT color=#800000 size=2>Graph:Graph</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theGraph</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>NodesBindingPath</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>ChildNodes</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </P> <P></FONT><FONT color=#ff0000 size=2>CoefficientOfDampening</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.7</FONT><FONT size=2>"</P></FONT><FONT color=#0000ff size=2> <P></FONT><FONT color=#ff0000 size=2>FrameRate</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.5</FONT><FONT size=2>"</P></FONT><FONT color=#0000ff size=2> <P></FONT><FONT color=#ff0000 size=2>NodeTemplateSelector</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{StaticResource nodeTemplateSelector}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Graph:Graph.Resources</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Style</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetType</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{x:Type Button}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Template</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter.Value</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ControlTemplate</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetType</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{x:Type Button}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Border</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theBorder</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>BorderBrush</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Gray</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>BorderThickness</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>2</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>CornerRadius</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>10</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Padding</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>5</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Background</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{TemplateBinding Background}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ContentPresenter</FONT><FONT color=#0000ff size=2>/&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Border</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ControlTemplate.Triggers</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>IsMouseOver</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetName</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theBorder</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>BorderBrush</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>#333333</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>/&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>IsPressed</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>TargetName</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>theBorder</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Property</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Background</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Value</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>#CCCCCC</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>/&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Trigger</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>ControlTemplate.Triggers</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>ControlTemplate</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Setter.Value</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Setter</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Style</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>x:Key</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>nodeTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Background</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>BurlyWood</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>CommandParameter</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding }</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Click</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>DisplayDetails</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>btnodeTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</FONT><FONT color=#0000ff size=2></P> <P>&lt;</FONT><FONT color=#800000 size=2>StackPanel</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Orientation</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Vertical</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Image</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Source</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.ImageUrl, Mode=OneWay, Converter={StaticResource ImageConverter}}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>ItemDisplayedImage</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Width</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>TextBlock</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Text</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.Name}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>FontSize</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>11</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>StackPanel</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>x:Key</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>PersonTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Background</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>BurlyWood</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>CommandParameter</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding }</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Click</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>DisplayDetails</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>btPersonTemplate</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Grid</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Grid.ColumnDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ColumnDefinition</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>ColumnDefinition</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Grid.ColumnDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Grid.RowDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>RowDefinition</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.1*</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>RowDefinition</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0.9*</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Grid.RowDefinitions</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Image</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Source</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.ImageUrl, Mode=OneWay, Converter={StaticResource ImageConverter}}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>ItemDisplayedImage</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Width</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Height</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>50</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Row</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.ColumnSpan</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>2</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>WindowsFormsHost</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>HostPresenceControl</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Row</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>1</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Column</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Margin</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>0,0,5,0</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>Presence:Persona</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Name</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>UserPresence</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>WindowsFormsHost</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;</FONT><FONT color=#800000 size=2>TextBlock</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Text</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>{Binding Path=Item.Name}</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Row</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>1</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>Grid.Column</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>1</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>FontSize</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>11</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 size=2>HorizontalAlignment</FONT><FONT color=#0000ff size=2>=</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2>Center</FONT><FONT size=2>"</FONT><FONT color=#0000ff size=2> /&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Grid</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>DataTemplate</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Graph:Graph.Resources</FONT><FONT color=#0000ff size=2>&gt;</P> <P>&lt;/</FONT><FONT color=#800000 size=2>Graph:Graph</FONT><FONT color=#0000ff size=2>&gt;</P></FONT> <P>And here is the DataTemplateSelector class associated to this XAML code:</P><FONT color=#0000ff size=2> <P>internal</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>class</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>NodeTemplateSelector</FONT><FONT size=2> : </FONT><FONT color=#008080 size=2>DataTemplateSelector</P></FONT><FONT size=2> <P>{</P> <P></FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>override</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2> SelectTemplate(</FONT><FONT color=#0000ff size=2>object</FONT><FONT size=2> item, </FONT><FONT color=#008080 size=2>DependencyObject</FONT><FONT size=2> container)</P> <P>{</P> <P></FONT><FONT color=#008080 size=2>Node</FONT><FONT size=2>&lt;</FONT><FONT color=#008080 size=2>Item</FONT><FONT size=2>&gt; node = item </FONT><FONT color=#0000ff size=2>as</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>Node</FONT><FONT size=2>&lt;</FONT><FONT color=#008080 size=2>Item</FONT><FONT size=2>&gt;;</P> <P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (node != </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>)</P> <P>{</P> <P></FONT><FONT color=#008000 size=2>// Select the correct NodeTemplate according to the type of the item</P></FONT><FONT size=2> <P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (node.Item.Type == </FONT><FONT color=#008080 size=2>ItemType</FONT><FONT size=2>.Person)</P> <P>{</P> <P></FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2> Template = ((</FONT><FONT color=#008080 size=2>FrameworkElement</FONT><FONT size=2>)container).FindResource(</FONT><FONT color=#800000 size=2>"PersonTemplate"</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>as</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2>;</FONT><FONT color=#008000 size=2></P></FONT><FONT size=2> <P></FONT><FONT color=#008080 size=2>Button</FONT><FONT size=2> btn = Template.FindName(</FONT><FONT color=#800000 size=2>"btPersonTemplate"</FONT><FONT size=2>, ???</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>as</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>Button</FONT><FONT size=2>;</P> <P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> (</FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2>)((</FONT><FONT color=#008080 size=2>FrameworkElement</FONT><FONT size=2>)container).FindResource(</FONT><FONT color=#800000 size=2>"PersonTemplate"</FONT><FONT size=2>);</P> <P>}</P> <P></FONT> <P><FONT color=#008000 size=2></P></FONT><FONT size=2></FONT><FONT color=#0000ff size=2>else <P></P></FONT><FONT size=2> <P>{</P> <P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> (</FONT><FONT color=#008080 size=2>DataTemplate</FONT><FONT size=2>)((</FONT><FONT color=#008080 size=2>FrameworkElement</FONT><FONT size=2>)container).FindResource(</FONT><FONT color=#800000 size=2>"nodeTemplate"</FONT><FONT size=2>);</P> <P>}</P> <P>}</P> <P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>;</P> <P>}</P> <P>}</P></FONT> <P>I want to ba able to access to the Button which is in my DataTemplate to do some binding on the WindowsFormsHost's Child (accessible using VisualTreeHelper class).</P> <P>But I don't know what I need to use here as a second parameter of the FindName mehod:</P> <P><FONT size=2><FONT color=#008080>Button</FONT> btn = Template.FindName(<FONT color=#800000>"btPersonTemplate"</FONT>, ???) <FONT color=#0000ff>as</FONT> <FONT color=#008080>Button</FONT>;</FONT></P> <P>&nbsp;</P> <P>Anyone have an idea ? Or maybe another/better idea ?</P> <P>&nbsp;</P> <P>&nbsp;</P> <P>Thanks !</P> <P>&nbsp;</P> <P>Thomas</P>Sat, 28 Oct 2006 11:10:26 Z2006-10-28T14:15:15Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#046e3e2e-a70a-4119-9755-7d62bf82ab78http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#046e3e2e-a70a-4119-9755-7d62bf82ab78Zhou Yonghttp://social.msdn.microsoft.com/Profile/en-US/?user=Zhou%20YongAcces to a button in a DataTemplateWell, FindName method expects a valid parent which the template is applied, the tricky part is that there is no MSDN documentation on who's the valid templated parent for data template, actually the valid templated parent for DataTemplate is ContentPresenter, so in your original xaml, you should first grab a  reference to the  ContentPresenter inside the control template, then pass that reference to the Template.FindName() method as the second parameter.<br><br>Sheva<br>Sat, 28 Oct 2006 12:05:10 Z2006-10-28T12:05:10Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#4a63919c-ad42-443b-bc1f-73698d24c067http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#4a63919c-ad42-443b-bc1f-73698d24c067Thomas LEBRUNhttp://social.msdn.microsoft.com/Profile/en-US/?user=Thomas%20LEBRUNAcces to a button in a DataTemplate<p>I've tri te following but I'm still having an error on the FindName method:</p> <p> </p><font color="#008080" size=2> <p>Graph</font><font size=2> graph = (</font><font color="#008080" size=2>Graph</font><font size=2>)</font><font color="#008080" size=2>VisualTreeHelper</font><font size=2>.GetParent(((</font><font color="#008080" size=2>FrameworkElement</font><font size=2>)container));</p> <p></font><font color="#008080" size=2>DataTemplate</font><font size=2> Template = graph.Resources[</font><font color="#800000" size=2>&quot;PersonTemplate&quot;</font><font size=2>] </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>DataTemplate</font><font size=2>;</p> <p></font><font color="#008080" size=2>Button</font><font size=2> btn = Template.FindName(</font><font color="#800000" size=2>&quot;btPersonTemplate&quot;</font><font size=2>, graph) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>Button</font><font size=2>;</font></p> <p><font size=2></font> </p> <p><font size=2></font> </p> <p><font size=2>:(</p></font>Sat, 28 Oct 2006 12:22:43 Z2006-10-28T12:22:43Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#fcb94e44-c817-4b17-8d1a-dbd84d90bc1ahttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#fcb94e44-c817-4b17-8d1a-dbd84d90bc1aThomas LEBRUNhttp://social.msdn.microsoft.com/Profile/en-US/?user=Thomas%20LEBRUNAcces to a button in a DataTemplate<p><div class=quote><table width="85%"><tr><td class=txt4> <strong>Zhou Yong wrote:</strong></td></tr><tr><td class=quoteTable><table width="100%"><tr><td width="100%" valign=top class=txt4>Well, FindName method expects a valid parent which the template is applied, the tricky part is that there is no MSDN documentation on who's the valid templated parent for data template, actually the valid templated parent for DataTemplate is ContentPresenter, so in your original xaml, you should first grab a  reference to the  ContentPresenter inside the control template, then pass that reference to the Template.FindName() method as the second parameter.<br><br>Sheva<br></td></tr></table></td></tr></table></div></p> <p> </p> <p>Based on your idea, I've triied the following:</p> <blockquote dir=ltr style="margin-right:0px"><font color="#008080" size=2> <p>Graph</font><font size=2> graph = (</font><font color="#008080" size=2>Graph</font><font size=2>)</font><font color="#008080" size=2>VisualTreeHelper</font><font size=2>.GetParent(((</font><font color="#008080" size=2>FrameworkElement</font><font size=2>)container));</p> <p></font><font color="#008080" size=2>Graph</font><font size=2>.</font><font color="#008080" size=2>GraphContentPresenter</font><font size=2> contentPresenter = (</font><font color="#008080" size=2>Graph</font><font size=2>.</font><font color="#008080" size=2>GraphContentPresenter</font><font size=2>)</font><font color="#008080" size=2>VisualTreeHelper</font><font size=2>.GetChild(graph, 0);</p> <p></font><font color="#008080" size=2>DataTemplate</font><font size=2> Template = graph.Resources[</font><font color="#800000" size=2>&quot;PersonTemplate&quot;</font><font size=2>] </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>DataTemplate</font><font size=2>;</p> <p></font><font color="#008080" size=2>Button</font><font size=2> btn = Template.FindName(</font><font color="#800000" size=2>&quot;btPersonTemplate&quot;</font><font size=2>, contentPresenter) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>Button</font><font size=2>;</p></font></div> <p>But still with the error:</p> <blockquote dir=ltr style="margin-right:0px"> <p><strong><em>This operation is valid only on elements that have this template applied.</em></strong></p></div> <p>Any ideas ?</p> <p> </p> <p>Thanks !</p> <p> </p> <p> </p> <p>Thomas</p>Sat, 28 Oct 2006 12:51:43 Z2006-10-28T12:51:43Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#a6cc40b6-c3c5-4407-be2a-7ae7de756576http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#a6cc40b6-c3c5-4407-be2a-7ae7de756576Thomas LEBRUNhttp://social.msdn.microsoft.com/Profile/en-US/?user=Thomas%20LEBRUNAcces to a button in a DataTemplate<p>OK, I've solved my problem using the LoadContent method of the DataTemplate:</p> <p> </p><font color="#008080" size=2> <p>DataTemplate</font><font size=2> Template = ((</font><font color="#008080" size=2>FrameworkElement</font><font size=2>)container).FindResource(</font><font color="#800000" size=2>&quot;PersonTemplate&quot;</font><font size=2>) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>DataTemplate</font><font size=2>;</p> <p></font><font color="#008080" size=2>Button</font><font size=2> btn = Template.LoadContent() </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>Button</font><font size=2>;</p> <p></font><font color="#008080" size=2>Grid</font><font size=2> grid = btn.Content </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>Grid</font><font size=2>;</p> <p></font><font color="#008080" size=2>WindowsFormsHost</font><font size=2> host = grid.Children[1] </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>WindowsFormsHost</font><font size=2>;</p> <p></font><font color="#008080" size=2>Persona</font><font size=2> UserPresence = host.Child </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>Persona</font><font size=2>;</p> <p>UserPresence.SipUri = node.Item.Email.ToLower();</p> <p> </p> <p> </p> <p>HTH</p> <p> </p> <p>Bye</p></font>Sat, 28 Oct 2006 14:15:08 Z2006-10-28T14:15:15Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#da02f839-3c4f-4175-901a-0e7c7d4c5bbbhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#da02f839-3c4f-4175-901a-0e7c7d4c5bbbZhou Yonghttp://social.msdn.microsoft.com/Profile/en-US/?user=Zhou%20YongAcces to a button in a DataTemplateAre you sure the contentPresenter you return is of ContentPresenter or is of ContentPresenter derivatives? or are you sure it's not  null?<br><br>Sheva<br>Sat, 28 Oct 2006 14:16:33 Z2006-10-28T14:16:33Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#edf5602e-8f14-423f-a7f6-edab761226c5http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e06a1d2b-f458-4e9b-8c71-04df332d5299#edf5602e-8f14-423f-a7f6-edab761226c5Thomas LEBRUNhttp://social.msdn.microsoft.com/Profile/en-US/?user=Thomas%20LEBRUNAcces to a button in a DataTemplateYes, the GraphContentPresenter class inherit from ContentPresenter.Sat, 28 Oct 2006 15:01:27 Z2006-10-28T15:01:27Z