我正在处理WPF App,我必须在其中实现用户控制并将其包含在我的项目中。我做到了,它在Designer视图中正确显示,但是当我运行它时,它没有显示。
用户控制代码:
<UserControl x:Class="facebook.showPost"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="400">
<Grid Margin="10">
<Label FontSize="20" Content="My label" />
</Grid>
</UserControl>
主窗口形式的窗口标签:
<Window x:Class="facebook.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:facebook"
mc:Ignorable="d"
MinWidth="400"
Background="#dfe3ee"
Closing="On_exit"
Title="facebook" Height="450" Width="800">
这就是我在主窗体中调用用户控件的方式:
<TabItem Header="New Item" >
<local:showPost />
</TabItem>
在设计器中,一切正常,但运行后,所有窗口均为空白。