There are similar topics here, but none of the resolutions have helped me.
I have the following:
<ControlTemplate x:Key="PlateWellControlTemplate"
TargetType="{x:Type ContentControl}">
<Grid x:Name="PART_stateGrid"
Margin="0,0,5,0">
<Ellipse Fill="#FF252526"
MinWidth="34"
MinHeight="34"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Ellipse x:Name="PART_stateControl"
Fill="#FFE6E6E6"
MinWidth="32"
MinHeight="32"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Label FontWeight="Bold"
FontFamily="Verdana"
Foreground="Black"
Background="#00000000"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalAlignment="Center"
Content=""/>
</Grid>
</ControlTemplate>
Used here:
<DataGridTemplateColumn Header="2">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Tag="{Binding WellX2}"
x:Name="wellX2"
MouseDown="well_Click">
<ContentControl Template="{DynamicResource PlateWellControlTemplate}"/>
Then accessed here in code-behind:
DataTemplate cellTemplate = (DataTemplate)cell.Template.FindName("PART_stateControl", cell);
Where "cell" is a non-null DataGridCell using the template. The above line always returns null and I do not understand why. I have also tried as a ControlTemplate and a ContentPresenter.
What I need is a reference to the Ellipse ("PART_StateControl") in the DataGridCell I've been handed as I need to change one of it's properties. But in general, how do I get to named items in the ContentControl Template? This is all triggered by a click event on the parent Grid control referenced in the DataGridTemplateColumn.CellTemplate here named "wellX2". Again, there are a few discussions on here regarding this, but none have helped. I feel like there's something silly missing. This has to be doable.
Thanks in advance for any help you can afford.