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);
}
}
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhiaacah
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22