我正在使用 C# WPF 和 Material Design 。
我需要的 :
我正在嘗試為我的專案CornerRadius中ButtonAssist的任何一個設定。Button
問題:
我無法從Application.Resources.
我的 XAML:
<Window
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:MaterialDesignation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
x:Class="MaterialDesignation.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
</Window.Resources>
<Grid>
<!--I Want to Set Radius For All Buttons in My Projects like blow line ↓-->
<Button Content="Button" materialDesign:ButtonAssist.CornerRadius="30" HorizontalAlignment="Left" Margin="71,260,0,0" VerticalAlignment="Top" Width="237" Height="85" Background="#FF038BEA" BorderBrush="{x:Null}"/>
<Button Content="Button" Style="{StaticResource ResourceKey=Gerdy}" HorizontalAlignment="Left" Margin="410,129,0,0" VerticalAlignment="Top" Width="237" Height="85" Background="#FF038BEA" BorderBrush="{x:Null}"/>
<Button Content="Button" materialDesign:ButtonAssist.CornerRadius="{Binding Gerdy}" HorizontalAlignment="Left" Margin="71,129,0,0" VerticalAlignment="Top" Width="237" Height="85" Background="#FF038BEA" BorderBrush="{x:Null}"/>
</Grid>
我的 App.xaml :
<Application x:Class="MaterialDesignation.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:clr="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:MaterialDesignation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<Style x:Key="Gerdy" TargetType="{x:Type Button}">
<Style.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="materialDesign:ButtonAssist.CornerRadius" Value="30" />
</Style>
</Style.Resources>
</Style>
<clr:Byte x:Key="GerdyAsByte">30</clr:Byte>
<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>
這是我的完整 WPF 專案鏈接: https ://ufile.io/gt5dcjzh
請幫忙
uj5u.com熱心網友回復:
為此基于 MaterialDesign 樣式創建自定義隱式樣式(不帶x:Key),并且僅更改. 它將自動應用于范圍內的所有 s。ButtonCornerRadiusButtonAssistButton
為您的按鈕樣式創建一個單獨的資源字典,以便在 MaterialDesign 的資源字典之后添加它,否則它們將覆寫您的樣式,而不是您覆寫其默認樣式。另請注意,本地值將始終覆寫樣式中的值。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="materialDesign:ButtonAssist.CornerRadius" Value="30" />
</Style>
</ResourceDictionary>
然后將它們添加到MaterialDesign 資源字典MergedDictionaries 之后。
<Application x:Class="MaterialDesignation.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:clr="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:MaterialDesignation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<clr:Byte x:Key="GerdyAsByte">30</clr:Byte>
<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 Source="CustomButtonStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/425993.html
