wpf - Accessing elements inside a DataTemplate in a TabItem -


Ok , I have a problem with a function that I get < Public Class TreeHelper Public Shared Function FindVisualChildByName (as the original DependencyObject, as the name string) (from the T-FrameworkElement form) I do not have anything for T = as the retarded child. I have to do the integer = 0 to VisualTreeHelper.GetChildrenCount (parent) - 1 dim ch = VisualTreeHelper.GetChild (parent, i) child = TryCast (ch, t) The baby does not have anything, and even child.Name isnot = for the name to exit again even if the child is not even then exit for the end if the next return child and function and class

and XML file:

  & lt; TabItem X: name = "itemControls" height = "50" margin = "0" verticalAlignment = "top" HorizontalContentAlignment = "muscles" VerticalContentAlignment = "muscles" padding = "6.1" & gt; & Lt; TabItem.HeaderTemplate & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt; Image x: name = "icon kb" width = "25" height = "25" extension = "fill" /> & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /TabItem.HeaderTemplate> & Lt; / TabItem & gt;   

So, I tried to edit the source of the iconKB image with the following syntax:

TreeHelper.FindVisualChildByName (of image) (itemControls, "iconKB "). Source = New Bitmap Image (New Yuri ("Pack: // application:, / Resources / Icons / Keyboard Page"))

But for some reason this does not change it's empty (And the problem is not in the new bitmap image (new "Yuri" ("pack: // app: ;, / resources / icons / keyboard page")) This completely resides with other image controls Checked out)

Thanks in advance.

That's because it's defined within the Datamplate's nameplate think about it, When you run your application, many of you can be and not all of them can be called icon kb.

EDIT: OK I checked your code, this is fine. The thing that does not behave correctly is that you try to find the element that is not yet in view screen because the tab is not opened. So the image is not found. This will work as you type in the loaded event handler.

  Private Shadow sub TSLoaded () handle tabSettings.Loaded TreeHelper.FindVisualChildByName (of image) (itemControls, "iconKB"). Source = New BitmapImage (new "Uri" (Pack: // application: ,,, / resource / mouse / Keyboard.png ")) TreeHelper.FindVisualChildByName (of the image) (itemMouse," iconMouse ") Source = New BitmapImage (". Pack: // application:., / Resources / icons / mouse page")) TreeHalper.FunvertVisual Channelname (image) (item audio, "icon audio"). Source = New Bitmap Image (New Yuri ("Pack: // Application: Source = New Bitmap Image (" Pack: // Application:, / Resources / Source / New Bitmap Image (New Yuri ("Pack: // Application: , / Resources / icon / settings.png ")" project ") ending sub    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -