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);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要创建C# WPF的Windows窗体应用程序,可以按照以下步骤进行操作。首先,在Visual Studio中选择“文件”->“新建”->“项目”命令,弹出项目对话框。在该对话框中选择“WPF应用程序”,并设置项目名称、位置等信息,然后点击“确定”按钮。接下来,在项目文件夹中会有一个默认的窗体程序MainWindow.xaml和MainWindow.xaml.cs。在MainWindow.xaml中,可以使用XAML语言来设计窗体的布局和界面元素。例如,可以使用StackPanel来放置按钮和文本块等控件。在MainWindow.xaml.cs文件中,可以编写C#代码来处理窗体的事件和逻辑。例如,可以在窗体加载时设置控件的属性,或者在按钮点击事件中执行相应的操作。最后,可以通过运行应用程序来查看窗体的效果。 #### 引用[.reference_title] - *1* *2* [C#创建Windows窗体应用程序](https://blog.csdn.net/weixin_50610118/article/details/113002325)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [C# WPF通过WindowChrome自定义窗体](https://blog.csdn.net/sD7O95O/article/details/127218714)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值