J P*_*J P 6 c# wpf mahapps.metro
看起来MahApps.Metro ProgressRing控件默认为最小尺寸为60x60.
ProgressRing有一个名为"IsLarge"的属性,但即使它被设置为"False",它似乎对能够使ProgressRing小于60x60没有影响.
不经意地改变高度和宽度属性也不会影响这一点.
将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>
Run Code Online (Sandbox Code Playgroud)
下面是GitHub上的"ProgressRing.cs"文件的代码片段- 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();
}
Run Code Online (Sandbox Code Playgroud)
编辑:MainWindow.xaml
<Grid>
<Controls:ProgressRing x:Name="PRing" IsLarge="False" MinHeight="15" MinWidth="15" Height="15" Width="15"></Controls:ProgressRing>
</Grid>
Run Code Online (Sandbox Code Playgroud)
编辑:MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
PRing.EllipseDiameter = 5;
}
}
Run Code Online (Sandbox Code Playgroud)
你必须找到一种风格ProgressRing并为自己设置Width和Height.对我来说,风格位于MahApps.Metro master \ MahApps.Metro \ Themes \ ProgressRing.xaml:
<Style TargetType="{x:Type Controls:ProgressRing}">
<Setter Property="Foreground" Value="{DynamicResource AccentColorBrush}"/>
<Setter Property="IsHitTestVisible" Value="False"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="MinHeight" Value="30"/>
<Setter Property="MinWidth" Value="30"/>
...
Run Code Online (Sandbox Code Playgroud)
默认情况下,也有Width和Height的60.据我所知,简单设置Width并Height直接影响省略号.
EDIT:
什么会使戒指更小,你可以玩参数EllipseDiameter和EllipseOffset通过代码,因为XAML他们将不可用(作为私人).
private void SetEllipseDiameter(double width)
{
if (width <= 60)
{
EllipseDiameter = 3.0; // as default 6.0
}
else
{
EllipseDiameter = width * 0.1 + 6;
}
}
private void SetEllipseOffset(double width)
{
if (width <= 60)
{
EllipseOffset = new Thickness(0, 12, 0, 0); // as default 24
}
else
{
EllipseOffset = new Thickness(0, width * 0.4 + 12, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
EDIT2:
设定直径Ellipse可以如下进行.我们确实有属性EllipseDiametersetter public:
public double EllipseDiameter
{
get
{
return (double)GetValue(EllipseDiameterProperty);
}
set // default as private
{
SetValue(EllipseDiameterProperty, value);
}
}
Run Code Online (Sandbox Code Playgroud)
在SetEllipseDiameter检查大小时Ellipse,如果Width小于60则设置为6.0.我们发表评论.
private void SetEllipseDiameter(double width)
{
//if (width <= 60)
//{
// EllipseDiameter = 6.0;
//}
//else
//{
// EllipseDiameter = width * 0.1 + 6;
//}
}
Run Code Online (Sandbox Code Playgroud)
并在Style设置直径,Ellipse如:
<Setter Property="MinHeight" Value="30"/>
<Setter Property="MinWidth" Value="30"/>
<Setter Property="EllipseDiameter" Value="3.0" />
Run Code Online (Sandbox Code Playgroud)
同样的道理EllipseOffset.他也是第一次私人,并检查Width小于60:
private void SetEllipseOffset(double width)
{
// you can drop this check
if (width <= 60)
{
EllipseOffset = new Thickness(0, 24, 0, 0);
}
else
{
EllipseOffset = new Thickness(0, width * 0.4 + 24, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
锻造这些操作这些参数,您可以配置Width和Height的ProgressRing控制.
| 归档时间: |
|
| 查看次数: |
5698 次 |
| 最近记录: |