2017-02-05 3 views
1

StackPanel内のすべてのボタンが同じスタイルになりたい。StackPanelのすべてのボタンを同じようにスタイルする(UWP)

HTML/CSSのような同様の可能性はありますか?私は今、これを持っている場合は

CSS

.myBox Button{ 
    color: blue; 
} 

HTML

<div class="myBox"> 
    <button type="button">1</button> 
    <button type="button">2</button> 
    <button type="button">3</button> 
</div> 

:たとえば

、これはHTMLで青いクラスmyBoxとdiv要素内のすべてのボタンのテキストを作りますStackPanel、すべてのボタンテキストを青にするにはどうしたらいいですか?

<StackPanel Orientation="Vertical" x:Name="ManagerMenu"> 
    <Button x:Name="1" Content="1" /> 
    <Button x:Name="2" Content="2" /> 
    <Button x:Name="3" Content="3" /> 
</StackPanel> 
あなたは(Xなし=:キー)デフォルトを置くことによってこれを行うことができます

答えて

4

のStackPanel内のボタンのスタイル:

<StackPanel Orientation="Vertical" x:Name="ManagerMenu"> 
    <StackPanel.Resources> 
     <Style TargetType="Button"> 
     <Setter Property="Foreground" Value="Blue" /> 
      ... 
     </Style> 
    </StackPanel.Resources> 
    <Button x:Name="1" Content="1" /> 
    <Button x:Name="2" Content="2" /> 
    <Button x:Name="3" Content="3" /> 
</StackPanel> 

しかし、あなたがのために既存のスタイルでそれをベースにすることボタンを押すか、むしろフラットに見えます。

+0

私は私のStackPanelにこれを追加しよう: '<スタイルのTargetType = "ボタン"> ' エラーが発生しました:**スタイルの値をUIElementCollection型のコレクションまたはディクショナリに追加することはできません。 * – Laire

+0

あなたが正しいです、私は何かを忘れました。編集します。 –

関連する問題