我试图理解,为什么 WPF 控件或派生自控件的自定义控件永远不可见:
比如说,我们有以下内容:
<Window x:Class="WpfApplication13.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication13"
Title="MainWindow" Height="350" Width="525">
<DockPanel Name="dockPanel1" Background="LightBlue">
<Canvas DockPanel.Dock="Left" ToolTip="tt one" Width="200" Background="Blue">
<Control Background="Red" ToolTip="tt control" BorderBrush="Red" BorderThickness="5" Width="50" Height="100"></Control>
</Canvas>
<Button Content="two" DockPanel.Dock="Left" ToolTip="tt two" ></Button>
<!--<my:MyControl Background="Red" ToolTip="tt hello" BorderBrush="Red" BorderThickness="5"></my:MyControl>-->
<Control Background="Red" ToolTip="tt hello" BorderBrush="Red" BorderThickness="5"></Control>
</DockPanel>
</Window>
任何指示控件的存在 - 任何边框、任何工具提示、任何背景都不会被检测到。
为什么这样,以及如何使控件可见?
最佳答案
Control
类是可以模板化的控件的基类,但它本身并不定义模板。没有模板的控件没有可视化树,因此不会显示。
关于.net - WPF:隐形控制(?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5651004/