- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
看起来 MahApps.Metro ProgressRing 控件默认的最小尺寸为 60x60。
ProgressRing 有一个名为“IsLarge”的属性,但即使将其设置为“False”,它似乎也无法使 ProgressRing 小于 60x60。
显然,更改 Height 和 Width 属性也不会对此产生影响。
在 GitHUb 上看作为 ProgressRing 的实际 c# 代码,看起来有几个属性可以影响椭圆直径等,但这些属性是私有(private)属性,不能从外部调用设置。
我怎样才能把它变小?说 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”文件中的代码片段
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;
}
}
最佳答案
您必须为 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"/>
...
默认有60
的Width
和Height
。据我了解,简单设置 Width
和 Height
仅直接影响椭圆。
编辑:
什么会使环更小,您可以通过代码使用参数 EllipseDiameter
和 EllipseOffset
,因为 XAML 它们将不可用(如 私有(private))。
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);
}
}
EDIT2:
要设置Ellipse
的直径可以按如下方式完成。我们确实有属性EllipseDiameter
setter public:
public double EllipseDiameter
{
get
{
return (double)GetValue(EllipseDiameterProperty);
}
set // default as private
{
SetValue(EllipseDiameterProperty, value);
}
}
在 SetEllipseDiameter
中正在检查 Ellipse
的大小,如果 Width
小于 60,则设置 6.0。我们注释掉。
private void SetEllipseDiameter(double width)
{
//if (width <= 60)
//{
// EllipseDiameter = 6.0;
//}
//else
//{
// EllipseDiameter = width * 0.1 + 6;
//}
}
然后在 Style
中设置 Ellipse
的直径:
<Setter Property="MinHeight" Value="30"/>
<Setter Property="MinWidth" Value="30"/>
<Setter Property="EllipseDiameter" Value="3.0" />
EllipseOffset
也是如此。他也是,一开始是private,并检查小于 60 的 Width
:
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);
}
}
使用这些参数进行这些操作,您可以配置ProgressRing
控件的Width
和Height
。
关于c# - 缩小 MahApps.Metro 中的 ProgressRing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17774185/
我正在构建一个需要从互联网下载 RSS 数据的 Windows 8 应用程序。 有一个等待的 GetFeedsAsync() 方法负责此操作,在我的应用程序主页的(异步)LoadState 方法中调用
我的意图是,当用户单击一个按钮导航到另一个页面时,他将看到一个进度条,直到另一个页面完全加载为止。 我已经找到了很多关于这个主题的教程,但是它们都使用了代码隐藏。我希望能够不使用代码隐藏(如果可能)。
我正在编写一个小型 UWP 项目,也使用 MVVM 模式(MVVM Light 框架)进行学习,并且在许多场景和控件中遇到了绑定(bind)问题。 我已经努力将其中一个隔离到可用的迷你示例项目中 he
我想创建一个带有两个网格的自定义用户控件,我想在其中加载图像,并且在加载图像之前我想显示 progressRing 控件。当我添加第二个 ProgressRing 时出现问题。我的 XAML 如下所示
我正在使用 WPF 中的排序和分组填充 DataGrid,我想为用户实现一个进度指示器,让他们知道当前查询仍在后台运行。我正在尝试使用 Mahapps 的 ProgressRing 但我不知道如何实现
看起来 MahApps.Metro ProgressRing 控件默认的最小尺寸为 60x60。 ProgressRing 有一个名为“IsLarge”的属性,但即使将其设置为“False”,它似乎也
引用http://briandunnington.github.io/progressring-wp8.html对于进度指示器的一个有趣的新实现,我想使 ProgressRing 控件适应 Windo
Window 中有一个TreeView。我想在事件中从 ItemsSource 加载 TreeViewItems,同时显示 ProgressRing(MahApps.Metro.Controls)。
我是一名优秀的程序员,十分优秀!