2013-07-21 25 views
6

MahApps.Metro ProgressRingコントロールのデフォルトは最小サイズ60x60です。MahApps.MetroでProgressRingを小さくする

"IsLarge"と呼ばれるProgressRingのプロパティがありますが、 "False"に設定されていても、ProgressRingを60x60より小さくすることはできません。

また、高さと幅のプロパティを意識的に変更しても、これには影響しません。

ProgressRingの実際のC#コードとしてGitHUbを見ると、楕円の直径などに影響を及ぼすいくつかのプロパティがあるように見えますが、これらのプロパティはプライベートプロパティであり、外部呼び出しから設定することはできません。

これをもっと小さくするにはどうすればよいですか? 20x20または30x30と言ってもよろしいですか?

以下のコードでは、IsLarge = Falseと指定し、サイズを30x30に設定しますが、デフォルトでは60x60に設定されています。 MainWindow.xaml

<Grid> 
    <Controls:ProgressRing x:Name="PRing" IsLarge="False" MinHeight="15" MinWidth="15" Height="15" Width="15"></Controls:ProgressRing> 
</Grid> 

EDIT:以下

<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

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(); 
     } 

EDITで見つかった "ProgressRing.cs" ファイルからのコードの抜粋ですMainWindow.xaml.cs

public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
      PRing.EllipseDiameter = 5; 
     } 
    } 

答えて

7

あなたはProgressRingのスタイルを見つけて、自分でWidthHeightを設定する必要があります。 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"/> 

... 

60WidthHeightがあります。私が理解する限り、簡単なセットWidthHeightは、楕円だけに直接影響します。

EDIT:

XAMLは、彼らが(プライベートとして)使用することはできませんので、リングがさらに小さくなるだろう何を、あなたは、コードをパラメータEllipseDiameterEllipseOffsetで遊ぶことができます。

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公共ています:Widthは6.0を設定し、その後60未満であればSetEllipseDiameter

public double EllipseDiameter 
{ 
    get 
    { 
     return (double)GetValue(EllipseDiameterProperty); 
    } 

    set // default as private 
    { 
     SetValue(EllipseDiameterProperty, value); 
    } 
} 

は、Ellipseのサイズにチェックしています。我々はコメントする。

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のために行きます。プライベート最初であまりにも彼、、、および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コントロールのWidthHeightを設定することができます。

+0

MinHeightとMinWidthを設定しても動作していたようですが、現在の制限は30x30です!私が試してみると、それより小さいものは同じままで、楕円の円の直径のために必要な最小の高さ/幅があるので、私は推測していますか? ;-) –

+0

さらに、高さと幅、そしてminheightとminwidthを20x20に設定しようとしましたが、それでも30x30のままでした。 –

+0

@J P:楕円の幅/高さを小さくする必要がありますか?または、幅/高さを30x30未満に設定しますか?少ない場合は、どれくらい? –

関連する問題