Tags: binding, code, framework, lttogglebutton, microsoft, msdn, net, rc1, similar, software, studio, togglebuttonischecked, toltcvoice, visual, xkeyquotmyvoicequot

ToggleButton.IsChecked Binding issue!

On Microsoft » Microsoft Visual Studio

6,706 words with 4 Comments; publish: Wed, 26 Dec 2007 00:24:00 GMT; (30093.02, « »)

I'm using the .NET Framework 3.0 RC1, and in my code I have something similar to:

<c:Voice

x:Key="myVoice" />

...

<ToggleButton Content="Ready" Click="ToggleReadyState"

IsChecked="{Binding

Source={StaticResource myVoice}, Mode=OneWay,

Path=IsItPossibleToNotReady}" />

I want to bind from the read only "myVoice.IsItPossibleToNotReady" property to the "ToggleButton.IsChecked" property.

So, I use the OneWay mode.

The binding works well until I push the toggle button!!!

Here is a snippet you can use in the XamlPad to illustrate the issue:

<StackPanel>

<ToggleButton x:Name="myToggleButton"

Content="ToggleButton"

IsChecked="{Binding

IsChecked, ElementName=myCheckBox, Mode=OneWay}"/>

<CheckBox x:Name="myCheckBox"

Content="CheckBox"

IsChecked="{Binding

IsChecked, ElementName=myToggleButton, Mode=OneWay}"/>

</StackPanel>

Scenario:

  1. Check/uncheck the CheckBox, so the ToggleButton follows
  2. Click on the ToggleButton
  3. Now check/uncheck the CheckBox, the ToggleButton does not follow anymore!!!

Here, a TwoWay mode will be a workaround, but I am not interested since my IsItPossibleToNotReady property is read only.

Am I wrong or it is a XAML bug? Is there a XAML only workaround?

Thanks,

Siger

All Comments

Leave a comment...

  • 4 Comments
    • There is some discussion of the issue in this thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=658462&SiteID=1

      But if you have a read-only property, why bind to a non read-only interface element? I would suggest setting IsEnabled="False" to prevent pressing the button, however, in doing so, the checked state is no longer visible.

      - Doug

      #1; Tue, 04 Sep 2007 00:36:00 GMT
    • AFAIK, what happens is that when u initially click on the toggle button the binding on the toggle button is proer but when u are setting the value on the checkbox the binding to the togglebutton is lost.. so when u click on the checkbox you are just setting thte value.... there is no binding to the button... this happens for only one way bindings...

      #2; Tue, 04 Sep 2007 00:37:00 GMT
    • Ok, it seems to be the same issue, but it sounds like a bug!!

      Thank you very much for your quick answer,

      Siger

      #3; Tue, 04 Sep 2007 00:38:00 GMT
    • I also have this problem with one way binding before, and Ian Griffiths advices me to save binding before I set the value on the target, and restore the binding after I've done setting the value, although it's a solution, but I think it's too cumbersome, so finally I decide to define my read only property this way:
      public boolean IsSelected
      {
      get {return isSelected;}
      set {/*NOP*/} // This just lets the two way data binding work.
      }

      and I use the two way data binding here, any changes to the IsSelected property will be ignored, and it works perfectly

      Sheva
      #4; Tue, 04 Sep 2007 00:39:00 GMT