Visual Studio 2012 XAML Designer - Cannot add more than one item

烂漫一生 提交于 2021-02-04 18:41:06

问题


I'm new to VS 2012, and I have this issue every time I use the XAML Designer.

Every time I add an item (e.g. a RadioButton, and Image, a Label) to my window, it deletes the previous one.

As a result, I can have only one item in my window, I know it is absurd, what am I missing?

Here is the xaml of the window

<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>

Here is the xaml of the window after dragging an image on it (from the Toolbox)

<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:


As made clear by @Hans, I was trying to add multiple content items into a Window, in the XAML designer. This is just not possible so i had to:

1) Add a Grid to the Window.

2) Add any item to the grid.

It works, here is a sample code:

<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>


来源:https://stackoverflow.com/questions/13230785/visual-studio-2012-xaml-designer-cannot-add-more-than-one-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!