2016-11-14 3 views
0

안녕하세요 WPF에서 새로 생겼습니다. 모든 사용자가 동일한 텍스트를 모든 텍스트 상자에 추가 할 수 있도록 바인딩 색상을 정의하는 방법을 보여 줄 사람이 있는지 궁금합니다. 단 하나의 코드 만 변경하면됩니다. 각각의 개별적으로?모든 텍스트 상자에 배경색 바인딩

내 XAML 코드 : 이미 MyBackgroundColor 바인딩 을 시도 위에 당신이 볼 수 있듯이

<TextBox x:Name="txtBC_Copy" 
     materialDesign:HintAssist.Hint="Enter the items name that was scanned in" 
     Style="{StaticResource MaterialDesignFloatingHintTextBox}" 
     Margin="478,90,25,618" 
     FontSize="24" 
     Background="{Binding MyBackgroundColor}" 
     BorderBrush="#890C00FF" 
     FontWeight="Bold" 
     CaretBrush="#89000000" 
     BorderThickness="0,0,0,2" 
     Foreground="#DD000000" > 
     <TextBox.SelectionBrush> 
      <SolidColorBrush Color="#890C00FF" Opacity="0"/> 
     </TextBox.SelectionBrush> 
</TextBox> 

. 뒤에

코드 :

Private _myBackgroundColor As Color 
Public Property MyBackgroundColor() As Color 
    Get 
     Return _myBackgroundColor 
    End Get 
    Set 
     If Value <> _myBackgroundColor Then 
      _myBackgroundColor = Value 
     End If 
    End Set 
End Property 

Public Sub New() 
    InitializeComponent() 
    MyBackgroundColor = Colors.Red 
End Sub 

내가 무엇을 놓치고 .... 내가 응용 프로그램을 실행하고 나는 txtBC_Copy 텍스트 상자에 빨간색 배경을 볼 수 없습니다, 위의 사람들 모두를 사용하십니까?

답변

1
Background

유형 Brush, 그래서, 같은 코드를 변경 :

Private _myBackgroundColor As Brush 
Public Property MyBackgroundColor() As Brush 
    Get 
     Return _myBackgroundColor 
    End Get 
    Set 
     If Value <> _myBackgroundColor Then 
      _myBackgroundColor = Value 
     End If 
    End Set 
End Property 

Public Sub New() 
    InitializeComponent() 
    MyBackgroundColor = Brushes.Red 
End Sub 
+0

는 일이! 고마워요. – StealthRT