




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第WPF實(shí)現(xiàn)抽屜菜單效果的示例代碼Style
TargetType="controls:DrawerMenuItem"
Setter
Property="HorizontalContentAlignment"
Value="Stretch"
/
Setter
Property="Foreground"
Value="{Binding
RelativeSource={RelativeSource
AncestorType={x:Type
controls:DrawerMenu}},
Path=MenuItemForeground}"/
Setter
Property="SelectionIndicatorColor"
Value="{Binding
RelativeSource={RelativeSource
AncestorType={x:Type
controls:DrawerMenu}},
Path=SelectionIndicatorColor}"/
Setter
Property="Template"
Setter.Value
ControlTemplate
TargetType="controls:DrawerMenuItem"
Button
x:Name="PART_Button"
Height="44"
Command="{TemplateBinding
SelectionCommand}"
ToolTip="{TemplateBinding
Text}"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Grid
Grid.ColumnDefinitions
ColumnDefinition
Width="5"/
ColumnDefinition/
/Grid.ColumnDefinitions
Grid
Grid.ColumnSpan="2"
Grid
Width="300"
Grid.ColumnDefinitions
ColumnDefinition
Width="45"/
ColumnDefinition/
/Grid.ColumnDefinitions
Image
Grid.Column="0"
Source="{TemplateBinding
Icon}"
Margin="10,5,5,5"/
TextBlock
Text="{TemplateBinding
Text}"
Grid.Column="1"
Margin="10,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="{StaticResource
TitleFontSize}"
Foreground="{TemplateBinding
Foreground}"
TextWrapping="Wrap"/
/Grid
/Grid
Grid
Name="PART_ItemSelectedIndicator"
Grid.Column="0"
Background="{TemplateBinding
SelectionIndicatorColor}"
Visibility="Collapsed"
/
/Grid
/Button
ControlTemplate.Triggers
Trigger
Property="IsSelected"
Value="True"
Setter
TargetName="PART_ItemSelectedIndicator"
Property="Visibility"
Value="Visible"
/
/Trigger
Trigger
SourceName="PART_Button"
Property="IsPressed"
Value="True"
Trigger.ExitActions
BeginStoryboard
Storyboard
BooleanAnimationUsingKeyFrames
Storyboard.TargetProperty="IsSelected"
DiscreteBooleanKeyFrame
KeyTime="00:00:00"
Value="True"
/
/BooleanAnimationUsingKeyFrames
/Storyboard
/BeginStoryboard
/Trigger.ExitActions
/Trigger
/ControlTemplate.Triggers
/ControlTemplate
/Setter.Value
/Setter
/Style
Style
TargetType="controls:DrawerMenu"
Setter
Property="Width"
Value="50"/
Setter
Property="Visibility"
Value="Visible"/
Setter
Property="IsOpen"
Value="True"/
Setter
Property="Template"
Setter.Value
ControlTemplate
TargetType="controls:DrawerMenu"
Grid
Background="{TemplateBinding
Background}"
ToggleButton
HorizontalAlignment="Left"
Background="#333"
VerticalAlignment="Top"
Height="40"
Width="50"
IsChecked="{Binding
RelativeSource={RelativeSource
AncestorType={x:Type
controls:DrawerMenu}},
Path=IsOpen}"
Path
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="Uniform"
Width="20"
Fill="{TemplateBinding
MenuIconColor}"
Data="{StaticResource
PathMenu}"/
/ToggleButton
ListBox
ItemsSource="{TemplateBinding
Content}"
HorizontalAlignment="Left"
Margin="0,40,0,0"
VerticalAlignment="Top"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedIndex="0"/
/Grid
/ControlTemplate
/Setter.Value
/Setter
Style.Triggers
Trigger
Property="IsOpen"
Value="False"
Trigger.EnterActions
BeginStoryboard
Storyboard
DoubleAnimation
Storyboard.TargetProperty="Width"
To="180"
Duration="0:0:0.2"/
/Storyboard
/BeginStoryboard
/Trigger.EnterActions
Trigger.ExitActions
BeginStoryboard
Storyboard
DoubleAnimation
Storyboard.TargetProperty="Width"
To="50"
Duration="0:0:0.2"/
/Storyboard
/BeginStoryboard
/Trigger.ExitActions
/Trigger
/Style.Triggers
/Style
/ResourceDictionary
4)DrawerMenuExample.xaml代碼如下。
UserControl
x:
xmlns="/winfx/2006/xaml/presentation"
xmlns:x="/winfx/2006/xaml"
xmlns:mc="/markup-compatibility/2006"
xmlns:d="/expression/blend/2008"
xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews.DrawerMenu"
xmlns:wpfdev="/WPFDevelopersOrg/WPFDevelopers"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
Grid
Background="#FF7B7BFF"
Grid.ColumnDefinitions
ColumnDefinition
Width="Auto"/
ColumnDefinition/
/Grid.ColumnDefinitions
wpfdev:DrawerMenu
Background="#eee"
SelectionIndicatorColor="{StaticResource
PrimaryPressedSolidColorBrush}"
MenuItemForeground="{StaticResource
BlackSolidColorBrush}"
HorizontalAlignment="Left"
wpfdev:DrawerMenu.Content
wpfdev:DrawerMenuItem
Icon="pack://application:,,,/Images/CircularMenu/2.png"
Text="主頁(yè)"
SelectionCommand="{Binding
HomeCommand,RelativeSource={RelativeSource
AncestorType=local:DrawerMenuExample}}"/
wpfdev:DrawerMenuItem
Icon="pack://application:,,,/Images/CircularMenu/4.png"
Text="Edge"
SelectionCommand="{Binding
EdgeCommand,RelativeSource={RelativeSource
AncestorType=local:DrawerMenuExample}}"/
wpfdev:DrawerMenuItem
Icon="pack://application:,,,/Images/CircularMenu/1.png"
Text="云盤"
SelectionCommand="{Binding
CloudCommand,RelativeSource={RelativeSource
AncestorType=local:DrawerMenuExample}}"/
wpfdev:DrawerMenuItem
Icon="pack://application:,,,/Images/CircularMenu/8.png"
Text="郵件"
SelectionCommand="{Binding
MailCommand,RelativeSource={RelativeSource
AncestorType=local:DrawerMenuExample}}"/
wpfdev:DrawerMenuItem
Icon="pack://application:,,,/Images/CircularMenu/6.png"
Text="視頻"
SelectionCommand="{Binding
VideoCommand,RelativeSource={RelativeSource
AncestorType=local:DrawerMenuExample}}"/
/wpfdev:DrawerMenu.Content
/wpfdev:DrawerMenu
Frame
Name="myFrame"
Grid.Column="1"
Margin="0,40,0,0"
NavigationUIVisibility="Hidden"/Frame
/Grid
/UserControl
5)DrawerMenuExample.xaml.cs代碼如下。
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Input;
using
System.Windows.Media;
using
WPFDevelopers.Samples.Helpers;
namespace
WPFDevelopers.Samples.ExampleViews.DrawerMenu
///
summary
///
Win10MenuExample.xaml
的交互邏輯
///
/summary
public
partial
class
DrawerMenuExample
:
UserControl
{
private
ListUri
_uriList
=
new
ListUri()
{
new
Uri("ExampleViews/DrawerMenu/HomePage.xaml",UriKind.Relative),
new
Uri("ExampleViews/DrawerMenu/EdgePage.xaml",UriKind.Relative),
};
public
DrawerMenuExample()
{
InitializeComponent();
myFrame.Navigate(_uriList[0]);
}
public
ICommand
HomeCommand
=
new
RelayCommand(obj
=
{
myFrame.Navigate(_uriList[0]);
});
public
ICommand
EdgeCommand
=
new
RelayCommand(obj
=
{
myFrame.Navigate(_uriList[1]);
});
public
ICommand
CloudCommand
=
new
RelayCommand(obj
=
{
WPFDevelopers.Minimal.Controls.MessageBox.Show("點(diǎn)擊了云盤","提示");
});
public
ICommand
MailCommand
=
new
RelayCommand(obj
=
{
WPFDevelopers.Minimal.Controls.MessageBox.Show("點(diǎn)擊了郵件","提示");
});
public
ICommand
VideoCommand
=
new
RelayCommand(obj
=
{
WPFDevelopers.Minimal.Controls.MessageBox.Show("點(diǎn)擊了視頻","提示");
});
}
6)HomePage.xaml.cs代碼如下。
Page
x:
xmlns="/winfx/2006/xaml/presentation"
xmlns:x="/winfx/2006/xaml"
xmlns:mc="/markup-compatibility/2006"
xmlns:d="/expression/blend/2008"
xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews.DrawerMenu"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
Title="HomePage"
Background="{StaticResource
PrimaryTextSolidColorBrush}"
Grid
TextBlock
VerticalAlignment="Center"
HorizontalAlignment="Center"
Width="400"
TextAlignment="Center"
TextWrapping="Wrap"
Margin="0,0,0,40"
FontSize="{StaticResource
NormalFontSize}"
Run
Foreground="White"Home/Run
Run
Text="微信公眾號(hào)
WPFDevelopers"
FontSize="40"
Foreground="#A9CC32"
FontWeight="Bold"/Run
LineBreak/
Hyperlink
NavigateUri="/WPFDevelopersOrg/WPFDevelopers.git"
RequestNavigate="GithubHyperlink_RequestNavigate"
Github
源代碼/Hyperlink
Run/
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 長(zhǎng)沙公司java面試題及答案
- 計(jì)算機(jī)軟件測(cè)試的團(tuán)隊(duì)協(xié)作模式試題及答案
- 教育政策與社會(huì)穩(wěn)定性的關(guān)系試題及答案
- 軟件設(shè)計(jì)師備考復(fù)習(xí)資料試題及答案
- 有效的公共政策實(shí)施策略試題及答案
- 突出重點(diǎn)的軟件設(shè)計(jì)師考試試題及答案
- 機(jī)電工程考試內(nèi)容概述及試題答案
- 網(wǎng)絡(luò)流量控制試題及答案
- 西方國(guó)家發(fā)展中的政治沖突試題及答案
- 項(xiàng)目管理師考試簡(jiǎn)易科目及試題答案
- 安徽合肥包河區(qū)演藝集團(tuán)有限責(zé)任公司招聘筆試題庫(kù)2025
- 湖北省武漢市江夏區(qū)2025屆九年級(jí)下學(xué)期5月月考語(yǔ)文試卷(含答案)
- 雨棚翻新合同協(xié)議書范文
- 2024年江蘇省無(wú)錫市中考?xì)v史真題(解析版)
- 消防安全知識(shí)培訓(xùn)試題及答案
- 閱讀策略在小學(xué)英語(yǔ)教學(xué)中的應(yīng)用
- 2025年黃山旅游發(fā)展股份有限公司春季招聘75人筆試參考題庫(kù)附帶答案詳解
- 2025年中考時(shí)事政治題及答案
- 江蘇省無(wú)錫市天一實(shí)驗(yàn)學(xué)校2024-2025學(xué)年七年級(jí)下學(xué)期期中歷史試題(原卷版+解析版)
- 2025年湖北長(zhǎng)江出版?zhèn)髅郊瘓F(tuán)長(zhǎng)江出版?zhèn)髅焦菊衅腹P試參考題庫(kù)含答案解析
- 2024年海南事業(yè)單位考試真題
評(píng)論
0/150
提交評(píng)論