2016-04-06 15 views
3

MahAppsライブラリのアイコンを通常のボタンに入れたいと思います。私はそれをこの方法を試してみました:ボタンにアイコンを入れる方法(MahApps)

次のように終了し
<Button Height="20" Width="25" Background="Transparent" Foreground="White" Content="{StaticResource appbar_close}"/> 

を、どのように私は、適切な位置にこのボタンには、このアイコンを統合することができますか?

+0

あなたは*のコードを表示することができますことができます* appbar_close **? 'Content =" {StaticResource appbar_close} "では、あなたは何を使っているのか分かりません。 – ganchito55

+1

このコードはMahAppsからビルドされています:http://mahapps.com/guides/icons-and-resources.html – chris579

答えて

14

によって提案されたと同じように...次のことを試すことができます。

まず、

<Button Width="50" 
     Height="50" 
     Style="{DynamicResource MetroCircleButtonStyle}"> 
    <Rectangle Width="20" 
       Height="20" 
       Fill="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}"> 
     <Rectangle.OpacityMask> 
      <VisualBrush Stretch="Fill" Visual="{DynamicResource appbar_close}" /> 
     </Rectangle.OpacityMask> 
    </Rectangle> 
</Button> 

アイコンrersources(MetroCircleButtonStyleとサンプル)を使用することができますし、2番目の新しいアイコンが

<Button Width="50" 
     Height="50" 
     Style="{DynamicResource MetroCircleButtonStyle}"> 
    <Controls:PackIconModern Width="20" Height="20" Kind="Close" /> 
</Button> 

役立ちます希望をパックします。私のアプリケーションで

3

あなたがgithub exampleで見ることができるように、彼らはボタン長方形を配置し、OpacityMaskプロパティを使用します。

Source

1

は、あなたが2つのオプションを持っている@ ganchito55

<Button Width="25" Height="20"> 
    <Button.Content> 
    <Rectangle Width="20" Height="20"> 
      <Rectangle.Fill> 
      <VisualBrush Visual="{StaticResource appbar_close}" Stretch="None" /> 
      </Rectangle.Fill> 
    </Rectangle> 
</Button.Content> 
</Button> 
0

アイコンとボタンのの多くを作成する前に、私はこのコードを使用:

<Button Command="{Binding EditDetailCommand}" ToolTip="Edit" Style="{DynamicResource buttonstyle}"> 
         <metro:PackIconModern Width="Auto" Height="Auto" Kind="Edit" /> 
        </Button> 

もう最新MahAppsでは動作しないようですか?

xamlファイルを埋めるだけで十分だと思うので、私は単純な構文が本当に好きです。

私はクリック可能なコントロールとしてのアイコンを持っていると思ったし、これはそれが最新Mahappsバージョンを私のためにどのように動作するかです
+0

新しい構文と古い構文との間には大きな違いはありません – chris579

+0

まあ、RectangleとVisualBrushはスタイルに含まれていますか? –

0

<Button Width="16" 
     Height="16" 
     Padding="0" 
     HorizontalAlignment="Right" 
     VerticalAlignment="Center" 
     Click="HelpButton_Click" 
     Style="{x:Null}" 
     Background="Transparent" 
     BorderThickness="0" 
     > 
    <Button.Content> 
     <Icons:PackIconMaterial Kind="Help" 
           VerticalAlignment="Center" 
           HorizontalAlignment="Center" /> 
    </Button.Content> 
</Button> 

・ホープこれは誰か

関連する問題