Visual Studio 2012 XAML Designer - 无法添加多个项目

时间:2012-11-05 11:05:04

标签: wpf xaml

我是VS 2012的新手,每次使用 XAML Designer 时都会遇到此问题。

每次我向我的窗口添加一个项目(例如RadioButton和Image,一个Label)时,它会删除前一个项目。

因此,我的窗口中只能有一个项目,我知道这是荒谬的,我错过了什么?

这是窗口的xaml

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="KinectSetupDev.MainWindow"
    Title="MainWindow" Height="400" Width="600">
    <Toolkit:KinectSensorChooserUI x:Name="SensorChooserUI" VerticalAlignment="Center" Height="40" Margin="277,2,275,328"/>
</Window>

这是在窗口上拖动图像后(从工具箱中)的窗口的xaml

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="KinectSetupDev.MainWindow"
    Title="MainWindow" Height="400" Width="600">
<Image HorizontalAlignment="Left" Height="86" Margin="77,188,0,0" VerticalAlignment="Top" Width="111"/>
</Window>

1 个答案:

答案 0 :(得分:5)

正如@Hans所说,我试图在XAML设计器中将多个内容项添加到窗口中。这是不可能的,所以我不得不:

1)向窗口添加网格。

2)将任何项目添加到网格中。

它有效,这是一个示例代码:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="KinectSetupDev.MainWindow"
    Title="MainWindow" Height="768" Width="1024" Loaded="Window_Loaded_1">
    <Grid HorizontalAlignment="Left" Height="736" VerticalAlignment="Top" Width="1012" Margin="2,2,0,0">
       <Image x:Name="Image01" HorizontalAlignment="Left" Height="240" Margin="136,27,0,0" VerticalAlignment="Top" Width="320"/>
       <TextBlock x:Name="tbMessages" HorizontalAlignment="Left" Height="60" Margin="10,606,-664,-426" TextWrapping="Wrap" VerticalAlignment="Top" Width="974"/>
       <WpfViewers:KinectColorViewer HorizontalAlignment="Left" Height="240" Margin="666,0,-666,0" VerticalAlignment="Top" Width="320"/>
    </Grid>
</Window>