当前位置: 首页 > news >正文

C# wpf程序

--App.xaml

namespace WpfMyproject
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            第二种方式
            //containerRegistry.RegisterForNavigation<AutoView>();
            //containerRegistry.RegisterForNavigation<ManuView>();
            //containerRegistry.RegisterForNavigation<SetView>();
            //containerRegistry.RegisterForNavigation<ParameterView>();
            //containerRegistry.RegisterForNavigation<StatisticView>();
            //containerRegistry.RegisterForNavigation<AlarmView>();
            //containerRegistry.RegisterForNavigation<UserView>();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new DirectoryModuleCatalog() {ModulePath = @".\Modules" };
        }
    }
}

--MainView.xaml

    <Window.Resources>
        <Style x:Key="MenuButtonStyle" TargetType="Button">
            <Setter Property="Margin" Value="5,5"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="60"/>
            <Setter Property="FontSize" Value="20"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Background" Value="#666666"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition/>
            <RowDefinition Height="60"/>
        </Grid.RowDefinitions>

        <Border Grid.Row="0" Background="#333366"/>
        <Border Grid.Row="2" Background="#cccccc"/>
        <Border Grid.Row="3" Background="Green"/>

        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition/>
                <ColumnDefinition Width="200"/>
            </Grid.ColumnDefinitions>

            <StackPanel Grid.Column="0">
                <TextBlock Margin="0,40" Text="图片" Width="100" FontSize="30" Foreground="Yellow" />
            </StackPanel>

            <StackPanel Grid.Column="2">
                <TextBlock Margin="0,20" Text="当前登录用户:" FontSize="18" Foreground="Purple"/>
            </StackPanel>

            <Grid Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0">
                    <TextBlock Margin="0,5" Text="智能控制系统" Width="100" FontSize="20" Foreground="White"/>
                </StackPanel>

                <StackPanel Grid.Row="1" Orientation="Horizontal">
                    <Button Style="{StaticResource MenuButtonStyle}" Content="自动" Command="{Binding OpenCommand}" CommandParameter="AutoView"/>
                    <Button Style="{StaticResource MenuButtonStyle}" Content="手动" Command="{Binding OpenCommand}" CommandParameter="ManuView"/>
                    <Button Style="{StaticResource MenuButtonStyle}" Content="设置" Command="{Binding OpenCommand}" CommandParameter="SetView"/>
                    <Button Style="{StaticResource MenuButtonStyle}" Content="参数" Command="{Binding OpenCommand}" CommandParameter="ParameterView"/>
                    <Button Style="{StaticResource MenuButtonStyle}" Content="统计" Command="{Binding OpenCommand}" CommandParameter="StatisticView"/>
                    <Button Style="{StaticResource MenuButtonStyle}" Content="报警" Command="{Binding OpenCommand}" CommandParameter="AlarmView"/>
                    <Button Style="{StaticResource MenuButtonStyle}" Content="登录" Command="{Binding OpenCommand}" CommandParameter="UserView"/>
                </StackPanel>
            </Grid>
        </Grid>

        <!--//第一种方式-->
        <!--<ContentControl Grid.Row="1" Content="{Binding Body}"/>-->
        
        <!--//第二种方式-->
        <ContentControl Grid.Row="1" prism:RegionManager.RegionName="ContentRegion"/>
    </Grid>


--MainViewModel

namespace WpfMyproject.ViewModels
{
    public class MainViewModel : BindableBase
    {
        //第一种方式
        //public DelegateCommand<string> OpenCommand { get; private set; }

        //public MainViewModel()
        //{
        //    OpenCommand = new DelegateCommand<string>(Open);
        //}

        //private object body;
        //public object Body
        //{
        //    get { return body; }
        //    set { body = value; RaisePropertyChanged(); }
        //}

        //private void Open(string obj)
        //{
        //    switch (obj)
        //    {
        //        case "AutoView": Body = new AutoView(); break;
        //        case "ManuView": Body = new ManuView(); break;
        //        case "SetView": Body = new SetView(); break;
        //        case "ParameterView": Body = new ParameterView(); break;
        //        case "StatisticView": Body = new StatisticView(); break;
        //        case "AlarmView": Body = new AlarmView(); break;
        //        case "UserView": Body = new UserView(); break;
        //    }
        //}

        //第二种方式
        private readonly IRegionManager regionManager;

        public DelegateCommand<string> OpenCommand { get; private set; }

        public MainViewModel(IRegionManager regionManager)
        {
            OpenCommand = new DelegateCommand<string>(Open);
            this.regionManager = regionManager;
        }

        private void Open(string obj)
        {
            regionManager.Regions["ContentRegion"].RequestNavigate(obj);
        }
    }
}

http://www.lryc.cn/news/108541.html

相关文章:

  • 4G WWAN设备类型
  • windows环境下安装elasticsearch、kibana
  • Java Selenium WebDriver 网页填报
  • 【NLP概念源和流】 06-编码器-解码器模型(6/20 部分)
  • 运维必备的免费在线画图工具,你觉得哪个最好用呢
  • skywalking全链路追踪
  • Nacos配置中心设置Mongodb
  • 【Spring Boot】请求参数传json对象,后端采用(map)CRUD案例(101)
  • 微软开测“Moment4”启动包:Win11 23H2要来了
  • SpringCloud《Eureka、Ribbon、Feign、Hystrix、Zuul》作用简单介绍
  • 运维项目—K8S命令
  • java框架整合Springmvc+···+maven
  • 答辩PPT怎么做?在线PPT软件哪个好?
  • Astro + Vercel 快速搭建自己的博客网站
  • TensorFlow
  • 【iOS RunLoop】
  • 阿里云平台注册及基础使用
  • Mr. Cappuccino的第58杯咖啡——MacOS配置Maven和Java环境
  • linux Ubuntu 更新镜像源、安装sudo、nvtop
  • LUN映射出错导致写操作不互斥的服务器数据恢复案例
  • Android 仿京东头部滚动头像动态变化
  • 高频交易学习——上期SimNow开通
  • 电力巡检无人机助力迎峰度夏,保障夏季电力供应
  • UOS环境python3.7及pyqt5安装
  • SEO优化:提升网站排名与流量的关键策略
  • flutter-GridView使用
  • Unity Shader编辑器工具类ShaderUtil 常用函数和用法
  • 详解Spring中涉及的技术
  • 阿里云ssl免费数字证书快过期 如何更换
  • 利用OpenCV实现图像拼接