0

Blacklight is an older set of WPF controls and styles. The code can be found here. It contains a control called AnimatedExpander which isn't really an expander, rather it just implements HeaderedContentControl and adds an IsExpandedProperty dprop:

    public static readonly DependencyProperty IsExpandedProperty =
       DependencyProperty.Register("IsExpanded", typeof(bool), typeof(AnimatedExpander), new PropertyMetadata(true));

    public bool IsExpanded
    {
        get
        {
            if (this.expandToggleButton != null)
            {
                return this.expandToggleButton.IsChecked.Value;
            }

            return (bool)GetValue(IsExpandedProperty);
        }

        set
        {
            SetValue(IsExpandedProperty, value);
        }
    }

I need to bind to IsExpanded so that I can persist whether expanders are expanded. I'm pretty sure I have the binding setup correctly, and that there is a problem with this custom dependency property. If I open the view in Snoop, and set the IsExpanded=True on the expander, the binding works. However, just clicking the expandToggleButton on the control only expands the control, it doesn't hit my binding.

    <controls:AnimatedExpander IsExpanded="{Binding SGGExpanderExpanded}" />

    private bool _sGGExpanderExpanded;
    public bool SGGExpanderExpanded
    {
        get { return _sGGExpanderExpanded; }
        set
        {
            if (_sGGExpanderExpanded != value)
            {
                _sGGExpanderExpanded = value;
                OnPropertyChanged("SGGExpanderExpanded");
            }
        }
    }

How can I bind to a value that changes when the user clicks the toggle button that is wired to expand the control?

JoeB
  • 2,743
  • 6
  • 38
  • 51
  • post the full code and XAML of that control. – Federico Berasategui Apr 04 '13 at 17:12
  • Thanks for the interest. The code is available at the link, and can be tested by simply binding one of the example AnimatedExpanders to a dummy viewmodel. As I have the bad solution I mentioned working, I can't afford to waste a bunch of time looking for a good solution right now. I'll try to come back on the weekend to find a pure MVVM solution. – JoeB Apr 04 '13 at 18:10
  • right. I'm almost sure that the problem you're having is due to a bad implementation in that control. – Federico Berasategui Apr 04 '13 at 18:14
  • Here's the control. I shared above what looked fishy to me (details in a dprop, which I know WPF can ignore). After more research I'm thinking some style is getting in the way. Here are the two files: http://blacklight.codeplex.com/SourceControl/changeset/view/15166#267951 http://blacklight.codeplex.com/SourceControl/changeset/view/15166#267944 – JoeB Apr 04 '13 at 18:20

1 Answers1

0

A bad solution:

I was able to make this work by attaching an event to the ToggleButton click and looking at the "sender" Content and IsChecked values to update my viewmodel.

JoeB
  • 2,743
  • 6
  • 38
  • 51