When theme change,the control tree is changed.
2011-03-30 11:59
405 查看
When use ListView, i want to find it's child :scrollViewer.use code as bellow:
when change theme from areo to non-aero ,for example as classic theme, application crash,the reason at above statement.
Use VisualTreeHelper to see VisualTree,The method as bellow:
When aero theme,visualTree is :
When non-aero theme,as classic, visualTree is :
the first child is different ,so when we use VisualTreeHelper like this,plase take care !~
the above statement should change as fllow:
var svALlItems = (ScrollViewer)(VisualTreeHelper.GetChild(listView1, 0) as Decorator).Child;
svALlItems = (ScrollViewer)(VisualTreeHelper.GetChild(lvAllItems, 0) as Border).Child;
when change theme from areo to non-aero ,for example as classic theme, application crash,the reason at above statement.
Use VisualTreeHelper to see VisualTree,The method as bellow:
string GetVisualTreeInfo(DependencyObject target) { int i = 0; int childCount = 0; DependencyObject parentObject = target; DependencyObject childObject = null; string format = "Rank:{0} childIndex:{1} {2} "; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("VisualTree:"); while (true) { childCount = VisualTreeHelper.GetChildrenCount(parentObject); if (childCount == 0) break; for (int j = 0; j < childCount; j++) { childObject = VisualTreeHelper.GetChild(parentObject, j); stringBuilder.AppendLine(string.Format(format, i, j, childObject)); } if (childObject == null) break; parentObject = childObject; i++; } Debug.WriteLine(stringBuilder.ToString()); return stringBuilder.ToString(); }
When aero theme,visualTree is :
Rank:0 childIndex:0 System.Windows.Controls.Border Rank:1 childIndex:0 System.Windows.Controls.ScrollViewer Rank:2 childIndex:0 System.Windows.Controls.Grid Rank:3 childIndex:0 System.Windows.Shapes.Rectangle Rank:3 childIndex:1 System.Windows.Controls.ScrollContentPresenter Rank:3 childIndex:2 System.Windows.Controls.Primitives.ScrollBar Minimum:0 Maximum:0 Value:0 Rank:3 childIndex:3 System.Windows.Controls.Primitives.ScrollBar Minimum:0 Maximum:0 Value:0
When non-aero theme,as classic, visualTree is :
Rank:0 childIndex:0 Microsoft.Windows.Themes.ClassicBorderDecorator Rank:1 childIndex:0 System.Windows.Controls.ScrollViewer Rank:2 childIndex:0 System.Windows.Controls.Grid Rank:3 childIndex:0 System.Windows.Shapes.Rectangle Rank:3 childIndex:1 System.Windows.Controls.ScrollContentPresenter Rank:3 childIndex:2 System.Windows.Controls.Primitives.ScrollBar Minimum:0 Maximum:0 Value:0 Rank:3 childIndex:3 System.Windows.Controls.Primitives.ScrollBar Minimum:0 Maximum:0 Value:0
the first child is different ,so when we use VisualTreeHelper like this,plase take care !~
the above statement should change as fllow:
var svALlItems = (ScrollViewer)(VisualTreeHelper.GetChild(listView1, 0) as Decorator).Child;
相关文章推荐
- When the layout is set to FIXED LAYOUT, the VERTICAL ALIGNMENT is not working. As soon as changed to
- When ESC is pressed, change the color of the character.
- Failed to load viewstate.The control tree into which viewstate is being loaded must match the control tree that......
- Setting an effect when the items in a data provider change on a List control in Flex
- [MST] Restore the Model Tree State using Hot Module Reloading when Model Definitions Change
- When bootstub get control, the memory map in DRAM is like
- The function default must be used with a prefix when a default namespace is not specified
- 【OpenCV学习笔记】【异常处理】一(The Matrix is not continuous, thus its number of rows can not be changed)
- WebRTC is almost here, and it will change the web
- Change my blog theme
- mysql5中大数据错误:Packet for query is too large (1117260 > 1048576). You can change this value on the ser
- 解决Vue请求 ‘No 'Access-Control-Allow-Origin' header is present on the requested resource’错误
- Solution For "could not be located or a different control is assigned to the same ID after postback"
- Is it possible kill a session when the browser is closed?
- 解决 js ajax跨域访问报“No 'Access-Control-Allow-Origin' header is present on the requested resource.”错误
- Event Handler to trigger User process tasks when the associated Organization is updated
- Light is falling on a tree from left side you have to find all the nodes on which this light will fa
- This kind of launch is configured to open the Debug perspective when it suspends.
- OMG, Silverlight! Asynchronous is Evil! (or, Call me back when you got it)
- Arrakis: The Operating System is the Control Plane(OSDI 2014)论文学习