트리거에서 다른 컨트롤의 속성에 바인딩하려면 어떻게 해야 합니까?
특히 TextBox의 IsReadOnly 속성에 바인드하여 버튼의 Content 속성을 설정합니다.둘 다 같은 스택패널의 일부입니다.
TextBox의 ElementName에 바인딩되어 있는 DataTrigger와 TextBox 이름을 SourceName으로 사용하는 트리거를 사용해 보았습니다.
무슨 생각 있어?
트리거를 유형의 일부로 지정해야 합니다. 버튼 자체의 트리거 집합은 이벤트 트리거만 포함할 수 있습니다.이를 염두에 두고 DataTrigger는 정상적으로 작동합니다.그러나 주름이 있습니다. 트리거 설정기의 값이 로컬 내용 속성을 덮어쓰지 않습니다.따라서 유형에서도 기본 내용을 설정해야 합니다.그 외관은 다음과 같습니다.
<Button> <!-- Note no content set directly on button -->
<Button.Style>
<Style TargetType="Button">
<Setter Property="Content" Value="You may write!!!" /> <!-- Here is the 'normal' content -->
<Style.Triggers>
<!-- Here is how we bind to another control's property -->
<DataTrigger Binding="{Binding IsReadOnly, ElementName=textBox}" Value="True">
<Setter Property="Content" Value="NO NO NO" /> <!-- Here is the 'override' content -->
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
이거 먹어봤어?
<StackPanel x:Name="LayoutRoot">
<Button Width="75" Content="{Binding IsReadOnly, ElementName=textBox, Mode=Default}" />
<TextBox x:Name="textBox" VerticalAlignment="Top" Text="TextBox" />
</StackPanel>
??
언급URL : https://stackoverflow.com/questions/2520483/how-do-i-bind-to-another-controls-property-from-a-trigger
'programing' 카테고리의 다른 글
WPF의 comboBox에 항목 추가 (0) | 2023.04.15 |
---|---|
WPF 슬라이더를 개별 정수 위치에만 스냅하려면 어떻게 해야 합니까? (0) | 2023.04.15 |
Excel vba를 사용하여 여러 기준 필터링 (0) | 2023.04.15 |
Excel VB에서 현재 셀 가져오기 (0) | 2023.04.15 |
브라우저에서 응용 프로그램을 실행하는 방법 (0) | 2023.04.15 |