【发布时间】:2013-07-21 16:01:46
【问题描述】:
看起来 MahApps.Metro ProgressRing 控件默认的最小尺寸为 60x60。
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>
下面是来自GitHub - MahApps.Metro上的“ProgressRing.cs”文件中的sn-ps代码
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;
}
}
【问题讨论】:
-
设置高度和宽度对我有用!设置两个属性,而不仅仅是一个!
标签: c# wpf mahapps.metro