(精华)2020年02月04日 WPF课程管理系统项目实战(平台布局-Tab切换页面)
【摘要】
页面代码
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignmen...
页面代码
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center">
<RadioButton Content="首页" Style="{StaticResource NavButtonStyle}" IsChecked="True"
Command="{Binding NavChangedCommand}"
CommandParameter="FirstPageView"/>
<RadioButton Content="关于我们" Style="{StaticResource NavButtonStyle}"/>
<RadioButton Content="课程中心" Style="{StaticResource NavButtonStyle}"
Command="{Binding NavChangedCommand}"
CommandParameter="CoursePageView"/>
<RadioButton Content="诚聘英才" Style="{StaticResource NavButtonStyle}"/>
<RadioButton Content="个人中心" Style="{StaticResource NavButtonStyle}"/>
</StackPanel>
<TextBox Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" Width="300" Height="32"
Template="{StaticResource SearchTextBoxTemplate}" Text="{Binding SearchText}" Foreground="White"/>
<ContentControl Grid.Row="2" Content="{Binding MainContent}"/>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
后台代码
public class MainViewModel : NotifyBase
{
public UserModel UserInfo { get; set; }
private string _searchText;
public string SearchText
{
get { return _searchText; }
set { _searchText = value; this.DoNotify(); }
}
private FrameworkElement _mainContent;
public FrameworkElement MainContent
{
get { return _mainContent; }
set { _mainContent = value; this.DoNotify(); }
}
public CommandBase NavChangedCommand { get; set; }
public MainViewModel()
{
UserInfo = new UserModel();
this.NavChangedCommand = new CommandBase();
this.NavChangedCommand.DoExecute = new Action<object>(DoNavChanged);
this.NavChangedCommand.DoCanExecute = new Func<object, bool>((o) => true);
DoNavChanged("FirstPageView");
}
private void DoNavChanged(object obj)
{
Type type = Type.GetType("命名空间." + obj.ToString());
ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
this.MainContent = (FrameworkElement)cti.Invoke(null);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
文章来源: codeboy.blog.csdn.net,作者:愚公搬代码,版权归原作者所有,如需转载,请联系作者。
原文链接:codeboy.blog.csdn.net/article/details/113622687
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)