I have created a CustonControl (NOT a usercontrol) and defined a DependencyProperty as following:

Public Shared ReadOnly HelpBrushProperty As DependencyProperty = DependencyProperty.Register("HelpBrush", GetType(String), GetType(ComboBox_with_helpBrush), New UIPropertyMetadata("Select..."), New ValidateValueCallback(AddressOf StringProp_Validate))

    Public Property HelpBrush() As String
        Get
            Return DirectCast(GetValue(HelpBrushProperty), String)
        End Get
        Set(ByVal value As String)
            SetValue(HelpBrushProperty, value)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("HelpBrush"))
        End Set
    End Property

    Private Shared Function StringProp_Validate(ByVal value As Object) As Boolean
        If Not (TypeOf value Is String) AndAlso value IsNot Nothing Then
            Return False
        End If
        Return True
    End Function

Then i added the Control Template into the ResourceDictionary and in one of my triggers i do this:

<Trigger Property="SelectedItem" Value="{x:Null}">
                            <Setter Property="Background" TargetName="ToggleButton" Value="{StaticResource HelpBrusher}"/>
                        </Trigger>

The HelpBrusher is a floowing defined:

<VisualBrush  x:Key="HelpBrusher" TileMode="None" Opacity="0.6" AlignmentX="Left" Stretch="None">
        <VisualBrush.Visual>
                               <TextBlock FontStyle="Italic" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ComboBox_with_helpBrush}}, Path=HelpBrush}" />
                          </VisualBrush.Visual>
    </VisualBrush>

And there i run into trouble to set the property since i cant access this control in code behind.

i have tried already the following things:

<TextBlock FontStyle="Italic" Text="{Binding HelpBrush, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />

 <TextBlock FontStyle="Italic" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ComboBox_with_helpBrush}}, Path=HelpBrush}" />

i added the control to a application and tested it like this:

<local:ComboBox_with_helpBrush Height="24" VerticalAlignment="Top" HelpBrush="test">
<local:customComboBoxItem>1</local:customComboBoxItem>
<local:customComboBoxItem>2</local:customComboBoxItem>
</local:ComboBox_with_helpBrush>

The default value ("Select...") is also set on the control.

I hope someone can enlight me how to access the property.

nvm made a workarround.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.