• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

C# wpf程序

武飞扬头像
WX_LW
帮助1

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhiaacah
系列文章
更多 icon
同类精品
更多 icon
继续加载