.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

CustomControl visualtreehelper.getchildrencount() always 0

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :WPF
I made a custom control of a listView with listviewitems and a gridview. But the VisualTreeHelper.GetChildrenCount() always returns 0. I need a way to get the children , so can anyone help me?

View Complete Post

More Related Resource Links

UserControl, CustomControl Design Time Support errors IOC, Dependency Injection, MVP

  Hi, is there a way to completely disable design time support for CustomControl, and UserControl ? I have about 30 UserControls and 10 CustomControls in my WinForms app, which contains some Dependency Injections and IOC stuff in constructors and Load handlers. I have lots of large UserControls containing smaller UserControls (CompositeView). All my UI code is pretty dynamic and the only thing i need to do at design time is to drag&drop containers in other containers (UserControls). And now i have a hard time doing this, because i have to wrap all constructors and Load Handlers in CurrentProccess!="devenv"... and when I'm Implementing some new View interface (which consist lots of properties) in UserControl all those properties by default throw NotImplementedException and i don't always need to implement them immediately but still i need to be able to run this code for testing. Besides, then i have to clean up designer generated class because it adds unnecessary null value property initializations, and then it way add some other ____ code, and so on.... Imagine UserControl with 10-15 nested UserControls, and then i try to open it in Form Designer and get ObjectReference NULL exception (for IOC) or some NotSupported NotImplemented exceptions (for properties) without adequate CallStack available! There is a CallStack but there is no trace in it to my Code (

VisualTreeHelper Problem

  I made partitions on my GUI using Expanders i am using datagrids with customized header styles .i want to change the contents of header on user selection from dropdown on top of the screen. But if Expander is not expanded once VisualTreeHelper.GetChildrenCount(parent);  where parent is datagird.   it returns 0.So i can  not change the header contents . I have to expand the expander once after that it works properly whether expander is expanded or collapsed, how to change contents of header of datagrid column without expanding the containing expander. Regards: Naseer

Error integrating a customcontrol in .NET 3.5

In have created a nullable datetimepicker for my project work. When I am referencing the same control in my forms, I am getting a strange problem.In the form.designer.cs, the system is not recognising the control and I need to appened gloabl:: to get the code working. Thats fine.Once I close the whole solution and try rebuilding the solution once again by taking latest from the VSS, the same problem ariese and I need to append global:: once again in the designer.csPlease give me some insights on the solutionThanks in advance,Crushed Onion

VisualTreeHelper.GetChildren() does not consider DateTenplates in Silverlight.


Hi Team,

I have used the following xaml in both WPF and Silverlight.



   <DataTemplate x:Key="template">

    <Border Background="Red">

     <ContentControl FontFamily="Comic Sans MS" Content="

CustomControl in seperate assembly problem with control template



I'm still not quite used to work with WPF, so this may be an easy question. But I have a problem.

I have just created a new CustomControl in my project. This custom control which inherits from a TextBox and has a template which defines the layout of the corresponding custom control. The template is referenced in the Generic.xaml as a MergedDictionary.

But, when I use this custom control in a another assembly, the template resource is not loaded, and I can't find out why. If I reference the template directly in the form that references the control it is displayed as it should, but not otherwise!

I have other controls that does work, just this one that doesn't...

Does anyone have any idea what I have forgot to do?

Here is the code of my template xaml:




When will VisualTreeHelper.GetDrawing() work?


I really need to use VisualTreeHelper.GetDrawing, but there seems to be no way to know when GetDrawing will return a non-null value. Many other posts have suggested that the Loaded event is a good place to start, but a simple test will show that this is not the case:


  <Button Loaded="Button_Loaded" />


And for code-behind:

Partial Public Class MainWindow

  Private Sub Button_Loaded(ByVal sender 

VisualTreeHelper.HitTest on UIElement that has been collapsed


In this simple WPF sample, the UIElement that has been collapsed at run-time still get reported by VisualTreeHelper.HitTest when another visible UIElement overlaps it.

To replicate:

  1. Copy the following code in a WPF application. Run the application.
  2. Notice the red ellipse is currently visible. Click Select button to collapse it.
  3. Click to where the red ellipse used to be.
  4. If you clicked where the blue ellipse and the red ellipse used to overlap, the red ellipse is still reported.
  5. If you clicked where only the red ellipse used to exist, the red ellipse is not reported.


<Grid x:Name="LayoutRoot" MouseLeftButtonDown="Grid_MouseLeftButtonDown">
<Ellipse x:Name=

CustomControls in CustomControl


Hello everybody!

I know the Subject sounds a bit stupid, but I don't know how to describe my problem. What makes use Google also not easy...

I want to create a Custom Servercontrol which have own Controls inside.


<My:CustomControl runat="server" ID="MyCustomControl1">
      <My:InlineTag Text="Example Text" />
              Hello Example Textblock

So how do I implement the InlineTag and TextBlock?

Thanks in advance! 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend