使用Sams 24小时WPF学习WPF / MVVM,但是在使我的代码正常工作时遇到了一些问题。
这是我到目前为止所拥有的:
注意:MainWindow1-名称更改为“ Shell”
代码:
<Window x:Class="ContactManager.Shell"
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:ContactManager"
xmlns:UserControls="clr-namespace:ContactManager.UserControls"
mc:Ignorable="d"
WindowState="Maximized"
WindowStyle="None">
<DockPanel>
<UserControls:SearchBar DockPanel.Dock="Top" />
<StatusBar DockPanel.Dock="Bottom">
<StatusBarItem DockPanel.Dock="Right">
<Slider x:Name="zoomSlider" Width="125" Value="1" Minimum=".5" Maximum="2" />
</StatusBarItem>
<StatusBarItem DockPanel.Dock="Right">
<TextBlock>Zoom:</TextBlock>
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="{Binding StatusText}" />
</StatusBarItem>
</StatusBar>
<Expander DockPanel.Dock="Left" ExpandDirection="Right" IsExpanded="True"
BorderThickness="0 1 1 1" BorderBrush="Gray" Margin="0 2 0 0"
Padding="2">
<Expander.Header>
<TextBlock Text="Contacts" FontSize="14" FontWeight="Bold">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90" />
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<UserControls:SideBar />
</Expander>
<TabControl x:Name="tabs" Grid.Column="2" Margin="5 0">
<TabControl.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=zoomSlider, Path=Value}"
ScaleY="{Binding ElementName=zoomSlider, Path=Value}" />
</TabControl.LayoutTransform>
</TabControl>
</DockPanel>
</Window>
我在项目中添加了一个名为“ UserControls”的文件夹
我创建了两个名为Searchbar和SideBar的用户控件。
代码:
搜索栏:
<UserControl x:Class="ContactManager.UserControls.Searchbar"
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"
xmlns:local="clr-namespace:ContactManager.UserControls"
mc:Ignorable="d">
<Grid>
...
</Grid>
</UserControl>
侧边栏:
<UserControl x:Class="ContactManager.UserControls.Sidebar"
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"
xmlns:local="clr-namespace:ContactManager.UserControls"
mc:Ignorable="d">
<Grid>
</Grid>
</UserControl>
错误如下:
我尝试使用工具箱将控件放到设计器上,并将XAML代码更新为:
<UserControls:Sidebar/>
尝试了各种方法使其正常运行,但是我对WPF的了解不足,使我无法自拔!知道我在做什么错吗?