本篇文章為大家展示了C#中怎么實(shí)現(xiàn)響應(yīng)式布局,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
成都創(chuàng)新互聯(lián)公司是一家網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè),提供網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),網(wǎng)站制作,建網(wǎng)站,按需定制,網(wǎng)站開發(fā)公司,成立與2013年是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價(jià)值為核心業(yè)務(wù),全程參與項(xiàng)目的網(wǎng)站策劃設(shè)計(jì)制作,前端開發(fā),后臺(tái)程序制作以及后期項(xiàng)目運(yùn)營(yíng)并提出專業(yè)建議和思路。
添加Nuget庫(kù)
使用 .Net Core 3.1 創(chuàng)建名為 “ResponsiveLayout” 的WPF解決方案,添加兩個(gè)Nuget庫(kù):MaterialDesignThemes和MaterialDesignColors。
MaterialDesign控件庫(kù)
3個(gè)文件變動(dòng):
App.xaml:添加MD控件樣式
MainWindow.xaml:主窗口實(shí)現(xiàn)效果
MainWindow.xaml.cs:主窗口后臺(tái)實(shí)現(xiàn)抽屜菜單開和閉
關(guān)鍵樣式引用代碼
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
全部代碼,菜單及右側(cè)布局
<Window x:Class="ResponsiveLayout.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ResponsiveLayout"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Storyboard x:Key="CloseMenu">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Width)" Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0" Value="200"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="70"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="OpenMenu">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Width)" Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0" Value="70"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="200"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Background="#FFCBCBCB" Grid.Column="1">
<Grid Margin="0 20 0 0" Background="#FFEEEEEE">
<Grid Height="100" Background="#FFEEEEEE" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border BorderBrush="White" BorderThickness="0 0 1 0" Grid.Column="0">
<TextBlock FontSize="30" Text="R$ 860,90" Foreground="Black" Margin="15"/>
</Border>
<Border BorderBrush="White" BorderThickness="0 0 1 0" Grid.Column="1">
<TextBlock FontSize="30" Text="R$ 750,90" Foreground="Black" Margin="15"/>
</Border>
<Border BorderBrush="White" BorderThickness="0 0 1 0" Grid.Column="2">
<TextBlock FontSize="30" Text="R$ 60,90" Foreground="Black" Margin="15"/>
</Border>
<Border BorderBrush="White" BorderThickness="0 0 1 0" Grid.Column="3">
<TextBlock FontSize="30" Text="R$ 865,90" Foreground="Black" Margin="15"/>
</Border>
</Grid>
</Grid>
</Grid>
<Grid x:Name="grid" Width="200" Background="#FF6C6C8D" RenderTransformOrigin="0.5,0.5" Grid.Column="0">
<Button x:Name="button" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" Style="{StaticResource MaterialDesignFlatButton}" Click="Button_Click">
<materialDesign:PackIcon Kind="Menu" Foreground="White"/>
</Button>
</Grid>
</Grid>
</Grid>
</Window>
關(guān)鍵代碼,簡(jiǎn)單的菜單開、閉動(dòng)畫播放
private void Button_Click(object sender, RoutedEventArgs e)
{
if (MenuClosed)
{
Storyboard openMenu = (Storyboard)button.FindResource("OpenMenu");
openMenu.Begin();
}
else
{
Storyboard closeMenu = (Storyboard)button.FindResource("CloseMenu");
closeMenu.Begin();
}
MenuClosed = !MenuClosed;
}
上述內(nèi)容就是C#中怎么實(shí)現(xiàn)響應(yīng)式布局,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
標(biāo)題名稱:C#中怎么實(shí)現(xiàn)響應(yīng)式布局
文章轉(zhuǎn)載:http://jinyejixie.com/article34/ggscse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、企業(yè)建站、Google、定制開發(fā)、、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)