2015-01-09 6 views
2

테두리의 색을 테두리의 라디오 단추 값에 바인딩하고 싶습니다. 버튼이 true 인 경우 - 선택됨 - 테두리의 기본 색상을 파란색에서 빨간색으로 변경하고 싶습니다.Silverlight 테두리 배경색 바인딩

<Border x:Name="RibbonMenuRight" 
    Background="Blue" 
    Margin="5"> 

     <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> 

<RadioButton Margin="0,0,0,10" 
     VerticalAlignment="Center" 
     HorizontalAlignment="Center" 
     GroupName="directions" 
     DataContext="{Binding UserSiteSettings}" 
     IsChecked="{Binding ExpanderLocation, ConverterParameter=Right,Converter=StaticResource ExpanderValueToBoolConverter}, Mode=TwoWay}" /> 

<TextBlock Text="Right " HorizontalAlignment="Center"/> 

</StackPanel> 
</Border> 

어떤 도움을

관련 에게 마이크

을 감상 할 수있다

답변

1
당신은 ElementName에이 컨버터와 결합 사용할 수 있습니다처럼 보이는

:

<Border x:Name="RibbonMenuRight" 
     Background="{Binding ElementName=ColorRadioButton,Path=IsChecked,Converter={StaticResource BoolToColorConverter}}" ...> 
    <Border.Resources> 
     <ResourceDictionary> 
      <local:BoolToColorConverter x:Key="BoolToColorConverter" /> 
     </ResourceDictionary> 
    </Border.Resources> 
</Border> 

<RadioButton x:Name="ColorRadioButton" ... /> 

컨버터는 해당 브러시를 반환해야합니다 :

public class BoolToColorConverter : IValueConverter 
{ 
    private static Brush _trueBrush = new SolidColorBrush(Colors.Red), 
     _falseBrush = new SolidColorBrush(Colors.Blue); 

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     bool isChecked = (value as bool?) ?? false; 
     return (isChecked ? _trueBrush : _falseBrush); 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
}