views:

324

answers:

1

I need to be able to set the Value of a setter to an attached property, but am having difficulty coming up with the syntax. This is what my trigger looks like:

<DataTrigger Binding="{Binding Path=IsDisabled}" Value="True">
    <Setter TargetName="LayoutRoot" Property="Opacity" Value="0.3" />
    <Setter TargetName="LayoutRoot" Property="Background" Value="Interaction:Behaviors.OriginalBgBrush" />
</DataTrigger>

where Interaction:Behaviors.OriginalBgBrush is the attached property set on LayoutRoot, and LayoutRoot is a Border. I'm having to do this because a standard Trigger above this one sets the Background, but there's no way for me to check values of a template and data trigger at the same time. Below is the entire template with the MultiTrigger being the one that sets the background where I don't want it to. Also the background color is defined in a separate style that uses this ControlTemplate as its' Template property.

<ControlTemplate x:Key="StandardRowStyle" TargetType="tk:DataGridRow">
    <Border x:Name="LayoutRoot" Margin="0,0,0,-1" MinHeight="23" Interaction:Behaviors.OriginalBgBrush="{TemplateBinding Background}" PreviewMouseRightButtonDown="DataGridRow_SimpleMouseDown" PreviewMouseLeftButtonDown="DataGridRow_SimpleMouseDown" Background="{TemplateBinding Background}" BorderBrush="{StaticResource ElementBorderBrush}" BorderThickness="1" CornerRadius="0" SnapsToDevicePixels="True">
        <toolkit:SelectiveScrollingGrid x:Name="DGR_SelectiveScrollingGrid">
            <toolkit:SelectiveScrollingGrid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </toolkit:SelectiveScrollingGrid.ColumnDefinitions>

            <toolkit:SelectiveScrollingGrid.RowDefinitions>
                <RowDefinition Height="*" MinHeight="23"/>
                <RowDefinition Height="Auto"/>
            </toolkit:SelectiveScrollingGrid.RowDefinitions>

            <toolkit:DataGridCellsPresenter Grid.Column="1" Grid.Row="0" x:Name="DGR_CellsPresenter" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
            <toolkit:DataGridDetailsPresenter Grid.Column="1" Grid.Row="1" Visibility="{TemplateBinding DetailsVisibility}" toolkit:SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding Path=AreRowDetailsFrozen, Converter={x:Static tk:DataGrid.RowDetailsScrollingConverter}, ConverterParameter={x:Static tk:SelectiveScrollingOrientation.Vertical}, RelativeSource={RelativeSource AncestorType={x:Type tk:DataGrid}}}" />
            <!--<toolkit:DataGridRowHeader Grid.Column="2" Grid.RowSpan="2" toolkit:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Visibility="{Binding Path=HeadersVisibility, Converter={x:Static tk:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static tk:DataGridHeadersVisibility.Row}, RelativeSource={RelativeSource AncestorType={x:Type tk:DataGrid}}}"/>-->
        </toolkit:SelectiveScrollingGrid>
    </Border>
    <ControlTemplate.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="True" />
                <Condition Property="IsSelected" Value="False" />
                <Condition Property="DetailsVisibility" Value="Collapsed" />     
            </MultiTrigger.Conditions>
            <Setter TargetName="LayoutRoot" Property="Background" Value="{StaticResource InactiveSelectedBackgroundBrush}" />
            <Setter TargetName="LayoutRoot" Property="BorderBrush" Value="{StaticResource InactiveOuterBorderBrush}" />
            <Setter TargetName="LayoutRoot" Property="CornerRadius" Value="5" />
        </MultiTrigger>            
        <DataTrigger Binding="{Binding Path=IsDisabled}" Value="True">
            <Setter TargetName="LayoutRoot" Property="Opacity" Value="0.3" />
            <!-- Background needs to be changed back to default here -->
        </DataTrigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
+1  A: 

Just use an ElementName binding:

<Setter TargetName="LayoutRoot"
        Property="Background"
        Value="{Binding Path=(Interaction:Behaviors.OriginalBgBrush), ElementName=LayoutRoot}" />
itowlson
Works like a charm, thanks.
thedesertfox