--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="當(dāng)前登錄用戶(hù):" 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="智能控制系統(tǒng)" Width="100" FontSize="20" Foreground="White"/>
? ? ? ? ? ? ? ? </StackPanel>
? ? ? ? ? ? ? ? <StackPanel Grid.Row="1" Orientation="Horizontal">
? ? ? ? ? ? ? ? ? ? <Button Style="{StaticResource MenuButtonStyle}" Content="自動(dòng)" Command="{Binding OpenCommand}" CommandParameter="AutoView"/>
? ? ? ? ? ? ? ? ? ? <Button Style="{StaticResource MenuButtonStyle}" Content="手動(dòng)" Command="{Binding OpenCommand}" CommandParameter="ManuView"/>
? ? ? ? ? ? ? ? ? ? <Button Style="{StaticResource MenuButtonStyle}" Content="設(shè)置" Command="{Binding OpenCommand}" CommandParameter="SetView"/>
? ? ? ? ? ? ? ? ? ? <Button Style="{StaticResource MenuButtonStyle}" Content="參數(shù)" Command="{Binding OpenCommand}" CommandParameter="ParameterView"/>
? ? ? ? ? ? ? ? ? ? <Button Style="{StaticResource MenuButtonStyle}" Content="統(tǒng)計(jì)" Command="{Binding OpenCommand}" CommandParameter="StatisticView"/>
? ? ? ? ? ? ? ? ? ? <Button Style="{StaticResource MenuButtonStyle}" Content="報(bào)警" 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;
? ? ? ? }文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-629331.html
? ? ? ? private void Open(string obj)
? ? ? ? {
? ? ? ? ? ? regionManager.Regions["ContentRegion"].RequestNavigate(obj);
? ? ? ? }
? ? }
}文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-629331.html
到了這里,關(guān)于C# wpf程序的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!