And well yes, maybe it's the weirdest think you ever hear...
But, after a change of my project's FW version, (from 4.5.1 to 4 and again to 4.5.1), a weird thing happens and is:
Basically, I have an image that I'm trying to change its source, that image is inside a DataTemplate, so I have to use FindVisualChild (I have 4 different functions that don't work http://pastebin.com/G3hAUPxa) for trigger that element via code...
The problem is, that the element is hooked before its container (a grid inside one of the tab items of a tab control) is loaded. (In other words, that image is hooked before I click on the Tab Item that contains the grid that contains the image)
I don't know why, but before it works well, as you can see there in this question.
And well, I have evidences of what I'm saying, because, if I handle the container (Grid) load, that is inside of a collapsed tab, it loads with the form, simply using a msgbox.
XAML code:
<TabControl x:Name="tabCSettings"
Height="400"
Margin="39,54,51,173"
Background="#00F9F9F9"
BorderBrush="#00DCDCDC">
<TabItem x:Name="itemOptions" Header="Opciones de juego">
<Grid x:Name="gameOptions"
Width="719"
Height="373"
Margin="0,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<TabControl x:Name="tabSettings"
Width="699"
Margin="10,35"
HorizontalAlignment="Center"
MouseLeftButtonUp="tabSettings_Click">
<TabItem x:Name="itemControls"
Height="50"
Margin="0"
VerticalAlignment="Top"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Padding="6,1">
<TabItem.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="iconKB"
Width="25"
Height="25"
Stretch="Fill" />
VB Code
Private Sub GridLoaded() Handles gameOptions.Loaded
MsgBox("Anything") 'That msgbox is called when the form loads, and before it doesn't happens, as you can see in the other question.
'And well, If I put anything here, by some reason it returns a NullReferenceException, and the function (FindVisualChild) is not wrong because yesterday after doing that crazy things it works correctly.
End Sub
The function I said in the comments can be found there and as you can see in the other question @Didier said that those are correct.
So, what can be happen?
Is there any event that handles control show? In WPF, MyBase.Shown not exists, I use .OnContentRendered(e) but not events are aviable for Grids...
So, what can I do?
Thanks in advance.