2012-01-06 4 views
1

텍스트 상자와 드롭 다운이 거의없는 화면 (Screen1.xaml)을 만들었습니다. 모든 텍스트 상자의 속성이 동일하므로, 나는 지금이동적으로 컨트롤 스타일 변경

<Style x:Key="TextBox.Base" TargetType="Control" BasedOn="{StaticResource TextBlock.Base}"> 
<Setter Property="Width" Value="250"/> 
<Setter Property="FontSize" Value="10"/> 
<Setter Property="Height" Value="15"/> 
<Setter Property="FontFamily" Value="Arial"/> 
</Style> 

같은 등 폭, 높이, 글꼴 크기와 같은 특성을 가진 스타일 파일 (stylesheet.xaml를) 만들었습니다 동적으로 변경하려면 일부 조건에 따라 컨트롤의 속성. 코드 숨김으로 무언가를하고 싶습니다. 도와주세요.

+0

새 Style 리소스를 적용하는 것이 중요합니까, 아니면 VisualStateManager가 필요한 것을 제공합니까? – terphi

답변

0

스타일을 선택하여 코드 숨김으로 변경할 수 있습니다. 스타일이 같은

// the style defined in the app.xaml (you need a key) 
Style globalStyle = Application.Current.Resources["Key"] as Style; 

// the style defined for a control (you need its key) 
UserControl control = ... 
Style controlStyle = control.Resources["Key"] as Style; 

// the current style of the control 
Style currentStyle = control.Style; 

변경 :

style.SetValue(UserControl.FontSizeProperty, (float)10); 

편집 : 지금 읽으면서 은, 스타일을 변경하려면 프로젝트에 포함 한 방법에 따라 여러 가지 방법이 있습니다 WPF에서이 컨트롤을 사용하는 모든 컨트롤에만 영향을 미칩니다. Silverlight에서는 모든 컨트롤의 속성을 변경할 수 있습니다. (

관련 문제