WPF按钮没有“点击”属性

时间:2013-11-29 04:54:34

标签: .net wpf .net-4.5

我是WPF的新手。我正在使用.NET 4.5。

出于某种原因,我的按钮在intellisense中没有Click属性。当我在下面输入它时,我在Blend中收到“无效标记”错误。

为什么这里没有Click属性?

我必须使用命令吗?

我的XAML:

<Window x:Class="Project.UI.Windows.windowLoadFiles"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Load Files" Height="350" Width="525">
    <DockPanel LastChildFill="True">
        <Menu DockPanel.Dock="Top" x:Name="menuMain" IsMainMenu="True" Height="Auto">
            <MenuItem Header="_File">
                <MenuItem x:Name="menuItem_Main_File_Exit" Header="E_xit" Click="menuItem_Main_File_Exit_Click"></MenuItem>
            </MenuItem>
        </Menu>
        <StackPanel Margin="10">
            <GroupBox Margin="5,0,5,5" Header="Source *" HorizontalAlignment="Stretch">
                <TextBox x:Name="textSourceDirectory"></TextBox>
                <Button x:Name="buttonSelectSourceDirectory" Content="Browse..." Click="buttonSelectSourceDirectory_Click"></Button>
            </GroupBox>
        </StackPanel>
    </DockPanel>
</Window>

1 个答案:

答案 0 :(得分:0)

正如上面提到的AjS,在Visual Studio中构建解决方案可以准确地解决问题。

GroupBox只能有一个子元素。这意味着如果您需要多个,则需要将它们添加到某种类型的Panel

以下解决了我的问题:

<Window x:Class="Project.UI.Windows.windowLoadFiles"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Load Files" Height="350" Width="525">
    <DockPanel LastChildFill="True">
        <Menu DockPanel.Dock="Top" x:Name="menuMain" IsMainMenu="True" Height="Auto">
            <MenuItem Header="_File">
                <MenuItem x:Name="menuItem_Main_File_Exit" Header="E_xit" Click="menuItem_Main_File_Exit_Click"></MenuItem>
            </MenuItem>
        </Menu>
        <StackPanel Margin="10">
            <GroupBox Margin="5,0,5,5" Header="Source *" HorizontalAlignment="Stretch">
                <StackPanel>
                    <TextBox x:Name="textSourceDirectory"></TextBox>
                    <Button x:Name="buttonSelectSourceDirectory" Content="Browse..." Click="buttonSelectSourceDirectory_Click"></Button>
                </StackPanel>
            </GroupBox>
        </StackPanel>
    </DockPanel>
</Window>