属性“内容”不止一次是WPF

时间:2016-11-02 13:46:39

标签: wpf

尝试运行此代码时出错。 错误是

  

属性'content'不止一次

当我包括`时出现问题

   Border BorderBrush="Transparent" BorderThickness="1" CornerRadius="15">
    </Border>

以下是完整代码:

 <Window
            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:WPF_test"
            xmlns:Properties="clr-namespace:WPF_test.Properties" x:Class="WPF_test.MainWindow"
            mc:Ignorable="d"
            Title="MainWindow" Height="248" AllowsTransparency="True" Width="459" WindowStyle="None" WindowStartupLocation="CenterScreen">
        <Window.Background>
            <ImageBrush ImageSource="Images/BlueBackground.jpg"/>
        </Window.Background>
        <Border BorderBrush="Transparent" BorderThickness="1" CornerRadius="15">
        </Border>
        <Grid Margin="0,0,2,2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="101*"/>
                <ColumnDefinition Width="348*"/>
            </Grid.ColumnDefinitions>

            <Label x:Name="label"  Foreground="White" Content="Login" HorizontalAlignment="Left" Margin="118,0,0,0" VerticalAlignment="Top" Height="51" Width="120" FontSize="36" FontFamily="Consolas" Grid.Column="1"/>
            <Label x:Name="label1" Foreground="White" Content="User Name" HorizontalAlignment="Left" Margin="105,79,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.474,1.808" FontSize="16" FontFamily="Consolas" Grid.Column="1" Height="29" Width="89"/>
            <Label x:Name="label2" Foreground="White" Content="Password" HorizontalAlignment="Left" Margin="105,123,0,0" VerticalAlignment="Top" FontSize="16" FontFamily="Consolas" Grid.Column="1" Height="29" Width="80"/>
            <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="209,129,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" Grid.Column="1"/>
            <TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="0" Margin="147,129,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="3" Grid.Column="1"/>
            <TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="23" Margin="209,82,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" Grid.Column="1"/>
            <Button x:Name="button" Content="Login" HorizontalAlignment="Left" Margin="105,180.525,0,0" VerticalAlignment="Top" Width="89" Height="27" FontFamily="Consolas" UseLayoutRounding="False" Grid.Column="1"/>
            <Button x:Name="button1" Content="Cancel" HorizontalAlignment="Left" Margin="240,181,0,0" VerticalAlignment="Top" Width="89" Height="27" FontFamily="Consolas" Grid.Column="1"/>
        </Grid>
    </Window>

任何人都可以帮我弄清问题是什么 谢谢

1 个答案:

答案 0 :(得分:6)

问题是,Window只能设置一个内容属性,并且您在Grid旁边添加了Border。而是尝试:

<Window
        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:WPF_test"
        xmlns:Properties="clr-namespace:WPF_test.Properties" x:Class="WPF_test.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="248" AllowsTransparency="True" Width="459" WindowStyle="None" WindowStartupLocation="CenterScreen">
    <Window.Background>
        <ImageBrush ImageSource="Images/BlueBackground.jpg"/>
    </Window.Background>
    <Border BorderBrush="Transparent" BorderThickness="1" CornerRadius="15">  
        <Grid Margin="0,0,2,2">
        ....
        </Grid>
    </Border>
</Window>

这样,BorderWindow的内容属性,而GridChild的{​​{1}}元素。