locked
WPF: Getting problem with Setter Property="Opacity" TargetName="bdr" RRS feed

  • Question

  • I am using Expression Blend and getting problem with Setter Property="Opacity" TargetName="bdr"

    Here it is showing that "The name bdr is not recognized"

    Here is the complete code:

    <Window
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="TestApp.MainWindow"
            Title="MainWindow" Height="600" Width="525">
       
        <Window.Resources>
           
            <Style x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid>
                                <Rectangle x:Name="Border" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" SnapsToDevicePixels="True"/>
                                <Polygon x:Name="Arrow" Fill="Black" HorizontalAlignment="Right" Margin="8,8,3,3" Opacity="0.15" Points="0,10 10,10 10,0" Stretch="Uniform" VerticalAlignment="Bottom"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Fill" TargetName="Border" Value="#FFFF0000"/>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter Property="Fill" TargetName="Border" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Visibility" TargetName="Arrow" Value="Collapsed"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="SysDataGridStyle" TargetType="{x:Type DataGrid}">
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                <Setter Property="BorderBrush" Value="#FF688CAF"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/>
                <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
                <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
                <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGrid}">
                            <Border x:Name="bdr" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
                                <ScrollViewer x:Name="DG_ScrollViewer" Focusable="false">
                                    <ScrollViewer.Template>
                                        <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>
                                                <Button Command="{x:Static DataGrid.SelectAllCommand}" Focusable="false" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                                                <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                                                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" Grid.ColumnSpan="2" Grid.Row="1"/>
                                                <ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="2" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Grid.Row="1" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}"/>
                                                <Grid Grid.Column="1" Grid.Row="2">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <ScrollBar x:Name="PART_HorizontalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/>
                                                </Grid>
                                            </Grid>
                                        </ControlTemplate>
                                    </ScrollViewer.Template>
                                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </ScrollViewer>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsGrouping" Value="true">
                        <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                    </Trigger>
                <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" TargetName="bdr" Value="0.7"/>
                </Trigger>
                </Style.Triggers>
            </Style>
           
        </Window.Resources>
       
       
        <StackPanel Orientation="Vertical" Margin="50,20">
                <ComboBox IsEnabled="False" x:Name="combo_test" Margin="0,0,0,15" />
                <DataGrid x:Name="datagrid_test"
                           ItemsSource="{Binding}"
                          Height="150"
                          Width="300"
                          Visibility="Visible"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Center" Style="{DynamicResource SysDataGridStyle}" />
                <Expander x:Name="expander_SystemManagement"
                          Margin="5"
                    Height="Auto"
                    Background="Transparent"
                    BorderThickness="1,0,1,1"
                    FontFamily="Arial"
                    FontSize="13"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    VerticalContentAlignment="Top"
                    Padding="6,6,0,6"
                  IsExpanded="True">
                        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="0,-10,0,0">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal"
                                FlowDirection="LeftToRight" Margin="14,0,0,0" Height="25">
                                    <Border x:Name="border" BorderBrush="#FF3565A3" BorderThickness="1">
                                        <Border.Background>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF7CB2FA" Offset="0"/>
                                                <GradientStop Color="#FF7CB2FA" Offset="1"/>
                                                <GradientStop Color="White" Offset="0.5"/>
                                            </LinearGradientBrush>
                                        </Border.Background>
                                        <Label x:Name="label_DeleteInactiveComputers"
                                           HorizontalContentAlignment="Left"
                                            VerticalContentAlignment="Center"
                                            Content="Lable 0"
                                            Cursor="Hand"
                                            Height="30"
                                            Width="200"
                                            Margin="5,0,0,0"
                                            ToolTip="" FontFamily="Calibri" FontSize="14.667" Padding="5,0" VerticalAlignment="Center" />
                                    </Border>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal"
                                    FlowDirection="LeftToRight" Margin="14,0,0,0">
                                    <Label x:Name="label_DeleteInactiveComputers1"
                                        HorizontalContentAlignment="Left"
                                        VerticalContentAlignment="Center"
                                        Content="Lable 1"
                                        Cursor="Hand"
                                        Height="30"
                                        Width="200"
                                        Margin="5,0,0,0"
                                        ToolTip="" FontFamily="Calibri" FontSize="14.667" />
                                </StackPanel>
                            </StackPanel>
                        </ScrollViewer>
                </Expander>
                <PasswordBox IsEnabled="False" HorizontalAlignment="Right" Margin="0,0,13.75,0" Width="107" Password="v"/>
            </StackPanel>
           
       
    </Window>

    Monday, August 22, 2011 11:49 AM

Answers

  • I believe that to reference bdr your trigger has to be in the ControlTemplate.Triggers collection, something like:

     

    	<ControlTemplate.Triggers>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Opacity" TargetName="bdr" Value="0.82"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    


    Monday, August 22, 2011 4:58 PM
    Moderator

All replies

  • I believe that to reference bdr your trigger has to be in the ControlTemplate.Triggers collection, something like:

     

    	<ControlTemplate.Triggers>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Opacity" TargetName="bdr" Value="0.82"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    


    Monday, August 22, 2011 4:58 PM
    Moderator
  • Thank you Sir...

    Your suggested code is really working...

    Thanks.

    Tuesday, August 23, 2011 2:06 PM