怎样建设网站内容,深圳建设网站开发,提高百度快速排名,现在装网线多少钱一年上一篇转载了RelativeSource的三种用法#xff0c;其中第二种用法较常见#xff0c;这里记录一下项目中曾经发生错误的地方#xff0c;以防自己哪天忘记了#xff0c;又犯了同样错误—WPF RelativeSource属性-CSDN博客
先回顾一下#xff1a;
控件关联其父级容器的属性—…上一篇转载了RelativeSource的三种用法其中第二种用法较常见这里记录一下项目中曾经发生错误的地方以防自己哪天忘记了又犯了同样错误—WPF RelativeSource属性-CSDN博客
先回顾一下
控件关联其父级容器的属性——AncestorType
详细介绍下AncestorLevel它指的是以Bingding目标控件为起点的层级偏移量S1的偏移量是1G2的偏移量是2G1是偏移量3AncestorType指的是要找的目标对象的类型。值得注意的是AncestorLevel必须参考AncestorType使用如上面设置了AncestorType{x:Type Grid}则Bingding在寻找时会忽略非Grid的控件此时G2的偏移量是1G1的偏移量是2StackPanel被忽略。
错误代码
TabControlTabItemWidth150Height30HeaderTabItem1IsSelectedTrueScrollViewer MaxHeight{Binding ActualHeight, RelativeSource{RelativeSource ModeFindAncestor, AncestorTypeTabItem, AncestorLevel1}}GridGrid.RowDefinitionsRowDefinition //Grid.RowDefinitionsGrid Grid.Row0TextBlockHorizontalAlignmentCenterVerticalAlignmentCenterFontSize100Text用户控件 //Grid/Grid/ScrollViewer/TabItem
/TabControl
Page界面显示效果文字显示不全只显示了高度为30的文字部分 问题出在这句话ScrollViewer MaxHeight{Binding ActualHeight, RelativeSource{RelativeSource ModeFindAncestor, AncestorTypeTabItem, AncestorLevel1}}
AncestorTypeTabItem往上查找第一个TabItem控件其Height30这样ScrollViewer的MaxHeight30直接造成显示不全
修
改前台代码AncestorTypeTabControl如下
TabControlTabItemWidth150Height30HeaderTabItem1IsSelectedTrueScrollViewer MaxHeight{Binding ActualHeight, RelativeSource{RelativeSource ModeFindAncestor, AncestorTypeTabControl, AncestorLevel1}}GridGrid.RowDefinitionsRowDefinition //Grid.RowDefinitionsGrid Grid.Row0TextBlockHorizontalAlignmentCenterVerticalAlignmentCenterFontSize100Text用户控件 //Grid/Grid/ScrollViewer/TabItem
/TabControl
Page界面显示效果文字显示完整所以使用RelativeSource查找目标类型 AncestorType时一定要仔细