리소스 객체의 속성을 컨트롤 (콤보 ...)에 바인딩하려고합니다. 디자이너에서 작동하는 것처럼 보이지만 작동하지 않습니다. 실행 시간. 그냥 단지 버튼 콤보와 함께 간단한 페이지를 사용하여 - 리소스 섹션 :Silverlight : 리소스 객체의 속성 바인딩
<UserControl.Resources>
<LinearGradientBrush x:Key="myBrush" EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Offset="0" Color="{Binding ElementName=w_comboColor, Path=SelectedItem.Content}" />
<GradientStop Offset="1" Color="White" />
</LinearGradientBrush>
</UserControl.Resources>
과 위젯 섹션 :
<Button Name="w_button" Grid.Row="0" Width="200" Content="Button" Height="60" HorizontalAlignment="Center"
Margin="2" VerticalAlignment="Center" Background="{Binding Source={StaticResource myBrush}}">
</Button>
<ComboBox Grid.Row="1" Height="24" HorizontalAlignment="Stretch" Margin="2"
Name="w_comboColor" VerticalAlignment="Center" SelectedIndex="1" >
<ComboBox.Items>
<ComboBoxItem Content="Red" />
<ComboBoxItem Content="Blue" />
<ComboBoxItem Content="Green" />
</ComboBox.Items>
</ComboBox>
콤보의 selectedIndex 속성의 값을 변경에서 디자이너가 버튼 배경을 배경색으로 변경합니다 (예상대로). 샘플을 실행하면 아무 것도 작동하지 않습니다. - \
나는 UserControl과 다른 것들의 DataContext를 강제 실행하려고 시도했습니다. 아무 일도 일어나지 않습니다 : 런타임시 바인딩이 깨졌습니다. 아이디어가 있으십니까?
안녕하세요. Stephan, 답변 해 주셔서 감사합니다. 사실 저는 이미 Gradient.Stop 바인딩에 Converter를 추가하려고 시도했지만 완전히 무시됩니다. 변환기를 사용하는 유일한 방법은 Gradient.Stop.Color를 코드 뒤에있는 Color DP에 바인드하고 Combo를 해당 DP에 변환기를 바인딩하는 것입니다. 물론 해당 문자열을 Color로 변환합니다. 하지만이 방법이 "순수 XAML"에서 어떻게 수행 될 수 있는지 이해하고 싶었습니다. 다른 측면에서는 "샘플"이 될 수 있기 때문입니다. 고객에게 제공 할 인프라의 –