它看起來像MahApps.Metro ProgressRing控件默認爲最小尺寸60x60。使MahApps.Metro中的ProgressRing更小
ProgressRing有一個名爲「IsLarge」的屬性,但即使它設置爲「False」,似乎也無法使ProgressRing小於60x60。
明顯改變Height和Width屬性也不會影響這個。
在GitHUb上查找ProgressRing的實際c#代碼,它看起來像有幾個屬性影響橢圓直徑等,但這些屬性是私有屬性,不能從外部調用設置。
我該如何縮小這個尺寸?說20x20或30x30?
在下面的代碼中,我指定了IsLarge = False,並將大小設置爲30x30,但仍然默認爲60x60。
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Orange.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Controls:ProgressRing IsActive="True" IsLarge="False" Height="30" Width="30"></Controls:ProgressRing>
</Grid>
</Window>
下面是從 「ProgressRing.cs」 文件的代碼段上GitHub - MahApps.Metro
namespace MahApps.Metro.Controls
{
[TemplateVisualState(Name = "Large", GroupName = "SizeStates")]
[TemplateVisualState(Name = "Small", GroupName = "SizeStates")]
[TemplateVisualState(Name = "Inactive", GroupName = "ActiveStates")]
[TemplateVisualState(Name = "Active", GroupName = "ActiveStates")]
public class ProgressRing : Control
private void SetMaxSideLength(double width)
{
MaxSideLength = width <= 60 ? 60.0 : width;
}
private void SetEllipseDiameter(double width)
{
if (width <= 60)
{
EllipseDiameter = 6.0;
}
else
{
EllipseDiameter = width * 0.1 + 6;
}
}
private void UpdateLargeState()
{
Action action;
if (IsLarge)
action =() => VisualStateManager.GoToState(this, "Large", true);
else
action =() => VisualStateManager.GoToState(this, "Small", true);
if (_deferredActions != null)
_deferredActions.Add(action);
else
action();
}
編輯發現:MainWindow.xaml
<Grid>
<Controls:ProgressRing x:Name="PRing" IsLarge="False" MinHeight="15" MinWidth="15" Height="15" Width="15"></Controls:ProgressRing>
</Grid>
編輯: MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
PRing.EllipseDiameter = 5;
}
}
設置MinHeight和MinWidth似乎工作,但現在的極限似乎是30x30!如果我嘗試去做比它小的事情,它會保持不變,我猜測是因爲必須有一些由於橢圓中圓的直徑而需要的最小高度/寬度? ;-) –
此外,我也嘗試設置高度和寬度以及minxight和minwidth到20x20,它仍然停留在30x30。 –
@J P:你需要減小橢圓的寬度/高度?或者設置寬度/高度小於30x30?如果少,那麼多少? –