Windows Vista Forums

Custom Dependency Property and Binding

  1. #1


    CSkinner Guest

    Custom Dependency Property and Binding

    I cannot get databinding to work with a custom property. I've simplified the
    situation in the following code. I'm trying to keep the currently selected
    item in a treeview in synch with the data being displayed in a custom
    control. The control in this case simply wraps a TextBlock for example
    purposes. I've include the xaml and code behind file. I'm simply using the
    control like this:

    <t:TestObject Grid.Row="1" Text2="{Binding ElementName=mProjectTree,
    Path=SelectedValue.Description}" />

    Please understand that if I use a normal TextBlock with the binding
    expression above, all works fine. I'm simply not doing something right in
    regards to setting up the DependencyObject. No runtime errors, I'm just not
    seeing the internal TextBlock's Text property being set ( so I never see the
    dependencypropertychanged event fire ). If I set the Text2 property
    manually, I do see the DependencyPropertyChanged event fire, so my break
    point in the OnChanged method on TestObject fires. But not in the data
    binding case.

    Thanks for any help,

    CS







      My System SpecsSystem Spec

  2. #2


    auto239436@hushmail.com Guest

    Re: Custom Dependency Property and Binding

    Can you post again without the encoded source?


      My System SpecsSystem Spec

  3. #3


    Nick Kramer [MSFT] Guest

    Re: Custom Dependency Property and Binding

    Does the debug output tell you anything useful? Data binding sends many
    nice messages to the debug output stream...

    -Nick Kramer [MSFT]
    http://blogs.msdn.com/nickkramer

    ---
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm


    "CSkinner" <cwskinner_no_sppaaam@comcast.net> wrote in message
    news:%23$BuCn1AGHA.1216@TK2MSFTNGP14.phx.gbl...
    >I cannot get databinding to work with a custom property. I've simplified
    >the situation in the following code. I'm trying to keep the currently
    >selected item in a treeview in synch with the data being displayed in a
    >custom control. The control in this case simply wraps a TextBlock for
    >example purposes. I've include the xaml and code behind file. I'm simply
    >using the control like this:
    >
    > <t:TestObject Grid.Row="1" Text2="{Binding ElementName=mProjectTree,
    > Path=SelectedValue.Description}" />
    >
    > Please understand that if I use a normal TextBlock with the binding
    > expression above, all works fine. I'm simply not doing something right in
    > regards to setting up the DependencyObject. No runtime errors, I'm just
    > not seeing the internal TextBlock's Text property being set ( so I never
    > see the dependencypropertychanged event fire ). If I set the Text2
    > property manually, I do see the DependencyPropertyChanged event fire, so
    > my break point in the OnChanged method on TestObject fires. But not in the
    > data binding case.
    >
    > Thanks for any help,
    >
    > CS
    >
    >
    >




      My System SpecsSystem Spec

  4. #4


    CSkinner Guest

    Re: Custom Dependency Property and Binding

    Nothing indicating what could be the problem...


    "Nick Kramer [MSFT]" <nkramer@ms.spam> wrote in message
    news:etykPfcBGHA.1088@tk2msftngp13.phx.gbl...
    > Does the debug output tell you anything useful? Data binding sends many
    > nice messages to the debug output stream...
    >
    > -Nick Kramer [MSFT]
    > http://blogs.msdn.com/nickkramer
    >
    > ---
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights. Use of included script samples are subject to the terms specified
    > at http://www.microsoft.com/info/cpyright.htm
    >
    >
    > "CSkinner" <cwskinner_no_sppaaam@comcast.net> wrote in message
    > news:%23$BuCn1AGHA.1216@TK2MSFTNGP14.phx.gbl...
    >>I cannot get databinding to work with a custom property. I've simplified
    >>the situation in the following code. I'm trying to keep the currently
    >>selected item in a treeview in synch with the data being displayed in a
    >>custom control. The control in this case simply wraps a TextBlock for
    >>example purposes. I've include the xaml and code behind file. I'm simply
    >>using the control like this:
    >>
    >> <t:TestObject Grid.Row="1" Text2="{Binding ElementName=mProjectTree,
    >> Path=SelectedValue.Description}" />
    >>
    >> Please understand that if I use a normal TextBlock with the binding
    >> expression above, all works fine. I'm simply not doing something right in
    >> regards to setting up the DependencyObject. No runtime errors, I'm just
    >> not seeing the internal TextBlock's Text property being set ( so I never
    >> see the dependencypropertychanged event fire ). If I set the Text2
    >> property manually, I do see the DependencyPropertyChanged event fire, so
    >> my break point in the OnChanged method on TestObject fires. But not in
    >> the data binding case.
    >>
    >> Thanks for any help,
    >>
    >> CS
    >>
    >>
    >>

    >
    >




      My System SpecsSystem Spec

Custom Dependency Property and Binding

Similar Threads
Thread Forum
Use my custom TypeDescriptor to obtains default Value on property inXAML Property Editor of Visual Studio 2008
Hello I just create an attached string property on my own class. I want use my own CustomTypeDescriptor on this property to show a comboBox...
Avalon
WPF: Autogenerate a Private Dependency Property ?
Hello. I frequently need to create private dependency properties to facilitate data binding. For example, I recently bound the "IsEnabled"...
.NET General
Binding to a custom dependency property
When the source's "MyColor" property is changed, the GraphPanel's "AxisColor" is not changed. This binding works fine if I use one of...
Avalon
Custom Dependency Property in custom class hierarchy not workingcorrectly?!
Hi everybody, I got a question on DPs. I want to provide 3 kinds of custom panels. Each panel has functionality and properties which are in...
Avalon
Trigger on user dependency property
I created a button that can be up, down, or "stuck down" for want of a better description. I created a new type that overrides Button and created...
Avalon
Paragraph.Text? Should there be a dependency property as well?
I'd like to set up databinding to a Paragraph object. Paragraph has a Text field, and I would like bind this to a particular cell in a DataTable. ...
Avalon
Dependency property not initialized in OnPropertyChanged?
I have made my own class that derives from ModelVisual3D called 'PlayfieldView'. To this class I added a dependency property called 'SlotModel' of...
Avalon