I have a simple XAML file with a grid in it and textboxes. But when using my code it does not find the textboxes by iteration.
VB.Net:
Dim ctl As FrameworkElement = Me.MainWindow
Code:
Dim ChildrenCount As Integer = VisualTreeHelper.GetChildrenCount(ctl)
'ChildrenCount is always zero
For i As Integer = 0 To ChildrenCount - 1
Dim Child As FrameworkElement = VisualTreeHelper.GetChild(ctl, i)
Call SetLanguageToControls(Keyword, cLanguage, Child)
Next
XAML:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Icon="/OUTPUT%20-%20Histogram;component/Sprectrum.ico">
<Grid x:Name="LayoutRoot">
<Grid x:Name="SpectrumContent" Margin="8" Height="120" Width="320">
<Rectangle Grid.Row="0" Grid.Column="1" Opacity="0.5">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Offset="0" Color="Black" />
<GradientStop Offset="1" Color="White" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock x:Name="txtRedMin" Text="|Red:" Foreground="Red" FontWeight="Bold" />
<TextBlock x:Name="txtRedMinValue" Text="000%" />
</Grid>
</Grid>
</Window>
EDIT
Problem is solved. I used the code while managing language in my plugins. But MainWindow1.Loaded was not called. If Window is not loaded, this code does not work. If Window is loaded, this code works.
You have to call your function recursively for each child control. That is, in the following line you get a child of
ctl:After this, you need to iterate over children of
Child.