기본적으로 텍스트박스의 스타일 아래와 같이 정의했다.

image

image

근데 특정 텍스트박스의 읽기를 못하게 초큼 간지나게 하고싶어서 스타일을 하나 만들었다.

image

image

근데 적용할땐 x:Key="IDTextBoxStyle" 키가 있으니깐 쉽게 적용되었는데

image

image

 

근데….

다시 원래의 전역으로 설정되는 스타일로  로 돌아갈려니 어케 돌아갸야 될지 난감 ㅡ_ㅡimage

찾다보니 방법이 아래와 같음

Style ts = Application.Current.FindResource(typeof(TextBox)) as Style;

 
        private void SetEnableMode(FrameworkElement fe, bool _Use)
        {
            Style UnEnableModeStyle = this.FindResource("IDTextBoxStyle") as Style; //사용안할때 스탈
            if (_Use)
            {             
                Style ts = Application.Current.FindResource(fe.GetType()) as Style; //기본  스탈로 돌아옴
                fe.Style = ts;      
              
            }
            else
            {                
                fe.Style = UnEnableModeStyle; //사용안함 설정                        
            }

            DependencyObjectType type = fe.DependencyObjectType;
            if (type.Name == "TextBox")
            {
               
                ((TextBox)fe).IsReadOnly = _Use ? false : true ;
            }

        }

+ Recent posts