I have a datagrid and in DataGridTemplateColumn, I have a togglebutton which when checked, it opens a Popup for comments with the help of ElementName binding.
<WpfToolkit:DataGridTemplateColumn>
<WpfToolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid >
<StackPanel Orientation="Vertical">
<ToggleButton Content="C" Name="toggleButon" VerticalAlignment="Center" Background="Transparent"></ToggleButton>
<Popup Height="Auto" Width="300" IsOpen="{Binding ElementName=toggleButon,Path=IsChecked}" StaysOpen="True" AllowsTransparency="True">
<Border BorderThickness="2" Background="LightGray">
<StackPanel Margin="20" Orientation="Vertical">
<TextBlock Text="Bloomberg Run Text Comment" Foreground="Black"></TextBlock>
<TextBox Text="check"/>
</StackPanel>
</Border>
</Popup>
</StackPanel>
</Grid>
</DataTemplate>
</WpfToolkit:DataGridTemplateColumn.CellTemplate>
</WpfToolkit:DataGridTemplateColumn>
It works as expected. But I am curious to know how the elementName binding is working at rowlevel because elementname of ToggleButton would be same for each row as I understand. So how the toggle button opens the popup window only within its scope and not any other popup window in any other row.
That is because the name should be unique within a given XAML namespace.
in WPF, templates have unique XAML namespace within root namespace.
http://msdn.microsoft.com/en-us/library/ms746659.aspx#Namescopes_in_Styles_and_Templates