国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

WPF實(shí)戰(zhàn)學(xué)習(xí)筆記04-菜單導(dǎo)航

這篇具有很好參考價(jià)值的文章主要介紹了WPF實(shí)戰(zhàn)學(xué)習(xí)筆記04-菜單導(dǎo)航。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

菜單導(dǎo)航

添加文件與文件夾

  • 添加文件夾

? ./Extensions

  • 添加文件[類(lèi)型:用戶控件]

    ./Views/IndexView.xaml

    ./Views/MemoView.xaml

    ./Views/TodoView.xaml

    ./Views/SettingsView.xaml

    ./ViewModels/IndexViewModel.cs

    ./ViewModels/IndexViewModel.cs

    ./ViewModels/IndexViewModel.cs

    ./ViewModels/IndexViewModel.cs

    ./Extensions/PrismManager.cs

建立View與ViewModel關(guān)聯(lián)

  • App.xaml.cs

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterForNavigation<IndexView, IndexViewModel>();
        containerRegistry.RegisterForNavigation<TodoView, TodoViewModel>();
        containerRegistry.RegisterForNavigation<MemoView, MemoViewModel>();
        containerRegistry.RegisterForNavigation<SettingsView, SettingsViewModel>();
    }
    

添加區(qū)域

定義區(qū)域名字
  • PrismManager.cs

    namespace Mytodo.Extensions
    {
        public static class PrismManager
        {
            public static readonly string MainViewRegionName = "MainViewRegion"; //定義Nanme變量 
        }
    }
    
注冊(cè)區(qū)域,綁定名字
  • MainView.xaml

    • 定義命名空間

      xmlns:ext="clr-namespace:Mytodo.Extensions"
      
    • 注冊(cè)控件區(qū)域

      <materialDesign:DrawerHost.LeftDrawerContent>
      <DockPanel>
      	<materialDesign:ColorZone...>
      	<ContentControl prism:RegionManager.RegionName="{x:Static ext:PrismManager.MainViewRegionName}" /> 
      </DockPanel>
      

添加導(dǎo)航

添加導(dǎo)航命令與變量
  • MainView.xaml.cs
private readonly IRegionManager regionManager;  //導(dǎo)航變量
public DelegateCommand<MenuBar> NavigateCmd { get; private set; } //導(dǎo)航命令
初始化導(dǎo)航命令
  • MainView.xaml.cs

    public MainViewModel(IRegionManager regm)
    {
        MenuBars=new ObservableCollection<MenuBar>();
        CreatMenuBar();
    
        //
        this.regionManager = regm;
        NavigateCmd = new DelegateCommand<MenuBar>(Navigate);
    }
    

    注意:初始化應(yīng)在構(gòu)造函數(shù)中

綁定導(dǎo)航命令
添加行為命名空間
  • main.xaml
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
添加行為,綁定導(dǎo)航命令
  • MainView.xmal
<i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectionChanged">
        <i:InvokeCommandAction Command="{Binding NavigateCmd}" CommandParameter="{Binding ElementName=menuBar, Path=SelectedItem}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

? 完整代碼為:

<ListBox
    x:Name="menuBar"
    HorizontalContentAlignment="Stretch"
    ItemContainerStyle="{StaticResource MyListboxItemStyle}"
    ItemsSource="{Binding MenuBars}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding NavigateCmd}" CommandParameter="{Binding ElementName=menuBar, Path=SelectedItem}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <materialDesign:PackIcon Kind="{Binding Icon}" />
                <TextBlock Margin="10,0" Text="{Binding Title}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

添加導(dǎo)航歷史功能

添加命令定義
  • MainviewModel.cs
public DelegateCommand GoBackCmd { get; private set; }
public DelegateCommand GoFwrdCmd { get; private set; }
添加導(dǎo)航歷史變量
  • MainviewModel.cs
private  IRegionNavigationJournal journal;		//導(dǎo)航歷史
初始化命令
  • MainviewModel.cs的構(gòu)造函數(shù)中添加
    //實(shí)例化命令
    GoBackCmd = new DelegateCommand(() =>
    {
        if (journal != null && journal.CanGoBack)
            journal.GoBack();
    });
    GoFwrdCmd = new DelegateCommand(() =>
    {
        if (journal != null && journal.CanGoForward)
            journal.GoForward();
    });
綁定命令
  • MainView.xaml

    <Button
        Margin="24,0,0,0"
        materialDesign:RippleAssist.Feedback="{Binding RelativeSource={RelativeSource Self}, Path=Foreground, Converter={StaticResource BrushRoundConverter}}"
        Command="{Binding GoFwrdCmd}"
        Content="{materialDesign:PackIcon Kind=ArrowLeft,
                                          Size=24}"
        Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"
        Style="{StaticResource MaterialDesignToolButton}"
        ToolTip="Previous Item" />
    
    <Button
        Margin="16,0,0,0"
        materialDesign:RippleAssist.Feedback="{Binding RelativeSource={RelativeSource Self}, Path=Foreground, Converter={StaticResource BrushRoundConverter}}"
        Command="{Binding GoBackCmd}"
        Content="{materialDesign:PackIcon Kind=ArrowRight,
                                          Size=24}"
        Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"
        Style="{StaticResource MaterialDesignToolButton}"
        ToolTip="Next Item" />
    
添加自動(dòng)關(guān)掉側(cè)欄代碼
  • MainView.xaml.cs文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-602976.html

    menuBar.SelectionChanged += (s, e) =>
    {
        drawerHost.IsLeftDrawerOpen = false;
    };
    

到了這里,關(guān)于WPF實(shí)戰(zhàn)學(xué)習(xí)筆記04-菜單導(dǎo)航的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記28-登錄界面

    添加登錄界面UI 添加文件loginview.xaml。注意本界面使用的是md內(nèi)的圖標(biāo)。沒(méi)有登錄界面的圖片 添加對(duì)應(yīng)的viewmodel 添加文件Mytodo.ViewModels.LoginViewModel.cs 注冊(cè)視圖 添加啟動(dòng) 修改文件:App.xmal.cs

    2024年02月14日
    瀏覽(14)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記16-數(shù)據(jù)加載

    新建Update事件,增加Prism事件列表 新建文件Mytodo/Common/Events/UpdateLoadingEvent.cs 新建含加載窗體基類(lèi) 新建文件Mytodo/ViewModels/NavigationViewModel.cs 建立數(shù)據(jù)加載窗體擴(kuò)展方法 新建文件Mytodo/Extensions/DialogExtension.cs 主窗口命名 修改文件Mytodo/Extensions/DialogExtension.cs 主窗口訂閱消息 修改文

    2024年02月15日
    瀏覽(22)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記23-首頁(yè)添加功能

    實(shí)現(xiàn)ITodoService、IMemoService接口,并在構(gòu)造函數(shù)中初始化。 新建 ObservableCollectionToDoDto 、 ObservableCollectionMemoDto 類(lèi)型的屬性,并將其綁定到UI中 修改Addtodo、Addmemo函數(shù),將添加功能添加 添加添加函數(shù) 修改文件:Mytodo.ViewModels.IndexViewModel.cs

    2024年02月15日
    瀏覽(21)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記31-登錄界面全局通知

    UI添加消息聚合器 注冊(cè)提示消息 文件:Mytodo.Views.LoginView.cs構(gòu)造函數(shù)添加內(nèi)容 在需要的地方添加提示消息 修改文件:Mytodo.ViewModels.LoginViewModel.cs

    2024年02月14日
    瀏覽(24)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記08-創(chuàng)建數(shù)據(jù)庫(kù)

    創(chuàng)建文件夾 ./Context 創(chuàng)建文件 ./Context/BaseEnity.cs ./Context/Memo.cs ./Context/MyTodoContext.cs ./Context/Todo.cs ./Context/User.cs 創(chuàng)建數(shù)據(jù)對(duì)象 ./Context/BaseEnity.cs ./Context/Memo.cs ./Context/MyTodoContext.cs 創(chuàng)建數(shù)據(jù)庫(kù)DbSet ./Context/Todo.cs ./Context/User.cs 添加nuget包 Microsoft.EntityFrameworkCore.Design Shared design-time co

    2024年02月16日
    瀏覽(46)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記10-創(chuàng)建todo接口

    新建控制器 新建文件 + webapi工程 ./Controllers/TodoController.cs 添加類(lèi) ### 新建服務(wù) #### 新建文件 + webapi工程 ./Service/ApiReponse.cs ./Service/IBaseService.cs ./Service/IToDoService.cs ./Service/ToDoService.cs 添加通用返回結(jié)果類(lèi) ApiReponse.cs 添加基礎(chǔ)接口 IBaseService.cs 添加todo接口 IToDoService.cs 添加TODO接口

    2024年02月16日
    瀏覽(17)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記06-設(shè)置待辦事項(xiàng)界面

    創(chuàng)建待辦待辦事項(xiàng)集合并初始化 TodoViewModel: 創(chuàng)建綁定右側(cè)命令、變量 設(shè)置界面

    2024年02月15日
    瀏覽(91)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記13-創(chuàng)建注冊(cè)登錄接口

    添加文件 創(chuàng)建文件 + MyToDo.Api ? ./Controllers/LoginController.cs ? ./Service/ILoginService.cs ? ./Service/LoginService.cs MyToDo.Share ./Dtos/UserDto.cs LoginController.cs ILoginService.cs LoginService.cs UserDto.cs 依賴(lài)注入 Program.cs 添加 AutoMapperProfilec.s 添加

    2024年02月15日
    瀏覽(48)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記24-首頁(yè)編輯與完成

    indexview添加Listbox控件的鼠標(biāo)雙擊行為 添加todo、memo的編輯命令 indexviewmodel添加對(duì)應(yīng)的更新事件處理 添加ToggleButton與后臺(tái)的綁定 將ToggleButton的ischeck綁定到status屬性 添加bool int 轉(zhuǎn)換器 添加完成命令 添加完成功能函數(shù) Listbox添加行為 給行為添加命令空間 文件:Mytodo.Views.IndexV

    2024年02月14日
    瀏覽(24)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記18-優(yōu)化設(shè)計(jì)TodoView

    修復(fù)新增項(xiàng)目無(wú)法編輯問(wèn)題 更新MyToDo.Api/Service/ToDoService.cs 更新MyToDo.Api/Service/MemoService.cs 增加了對(duì)完成狀態(tài)的區(qū)分 更新MyToDo.Api/Service/TodoView.xaml 增加了選項(xiàng)卡刪除功能 更新刪除請(qǐng)求URI 更新MyToDo.Api/Service/Baservice.cs 添加刪除命令并初始化 更新文件:MyToDo/ViewModel/TodoViewModel.cs

    2024年02月15日
    瀏覽(19)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包