2013-11-26 2 views
0

은 모든 시각적 스타일을 무시하지만 내가 그러나 나는 그런 marginsverticalAlignment 같은 시각적 것보다 다른 일부 속성을 설정하려면, 그래서 나는 UserControl.resources 섹션Mahapps 테마를 재정의하지 않고 속성을 설정하는 방법은 무엇입니까?

<Style x:Key="{x:Type TextBox}" TargetType="TextBox" BasedOn="{StaticResource ResourceKey={x:Type TextBox}}"> 
    <Setter Property="Margin" Value="2"/> 
    <Setter Property="VerticalAlignment" Value="Center"/> 
</Style> 

이 추가하는 GUI에 대한 Mahapps을 사용하고 있습니다 TextBoxes의 속성을 사용하면 모든 비주얼 스타일 설정을 재정의하지 않고 이러한 속성을 추가하는 방법은 무엇입니까?

+0

당신이 정의한'Key'가 일반적으로 모든'TextBox'를 목표로하는 단순한 이유로'TextBox'에 영향을 미칩니다. 대신'Key'에'Key = "SpecificTextBox"와 같은 일반 이름을 지정하십시오. 그런 다음 'TextBox'에 대한 xaml 정의에서이 스타일을 가리 키십시오. – Sandesh

답변

1

스타일에게 키

<Style x:Key="myCustomTextBoxStyle" 
     TargetType="TextBox" 
     BasedOn="{StaticResource ResourceKey={x:Type TextBox}}"> 
    <Setter Property="Margin" Value="2"/> 
    <Setter Property="VerticalAlignment" Value="Center"/> 
</Style> 

를주고 당신이

<TextBox Style={StaticResource myCustomTextBoxStyle} /> 

편집 또는 사용자 컨트롤이나 윈도우 자원의 주요 리소스 사전에 넣어없이 필요로하는 곳에 사용 키

<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 

     </ResourceDictionary.MergedDictionaries> 

     <Style TargetType="TextBox" 
       BasedOn="{StaticResource ResourceKey={x:Type TextBox}}"> 
      <Setter Property="Margin" Value="2"/> 
      <Setter Property="VerticalAlignment" Value="Center"/> 
     </Style> 
    </ResourceDictionary> 
</Window.Resources> 

ho pe 도움이

+0

답장을 보내 주셔서 감사합니다.하지만 각 구성 요소의 스타일을 설정하지 않으려합니다. – user2005494

+1

@ user2005494 키없이 스타일을 만들고 컨트롤이 호스팅되는 주 리소스 사전에 넣을 수 있습니다. – punker76

관련 문제