c#


WPF ToggleButton Binding Not Working


I have two ToggleButtons; I'm trying to make them behave like a pair of radio buttons by binding them to booleans, but it's not working. Here's what I have so far:
<ToggleButton Name="YesButton" Margin="5,0" Width="100" IsChecked="{Binding YesBool, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">Yes!</ToggleButton>
<ToggleButton Name="NoButton" Margin="5,0" Width="100" IsChecked="{Binding NoBool, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">No!</ToggleButton>
And
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = this;
InitializeComponent();
}
}
public class Thingy : INotifyPropertyChanged
{
private bool _yesno;
public bool YesBool
{
get { return _yesno; }
set { _yesno = value; NotifyPropertyChanged("YesBool"); }
}
public bool NoBool
{
get { return !_yesno; }
set { _yesno = !value; NotifyPropertyChanged("NoBool"); }
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
As far as I can tell, everyone else who had this problem misspelled their binding or didn't use NotifyPropertyChanged, but (as far as I can tell) I'm doing both of those things. What am I doing wrong?
Set your DataContext in your xaml to your Thingy class instead of "this" Window.

Related Links

Fluent.Ribbon buttons
Disable Auto-hide button on dockpanel-suite docked form
WCF - C# - SOAP How to change port name?
C# dataGridView update changes to database with another thread
Shorter method for checking ComboBoxItem has been selected
Fill texture brush using image, not tile
Selenium 3 Mozilla Firefox v 49 GeckoDriver Windows 10 ThrowTimeoutException
PushSharp stops at StopAllServices
DropdownList in EmptyDataRow and Footer data bind with SQL stored procedure
How to update Clear Case view using .Net?
The requested service has not been registered
C# Dynamically Map File System Using Recursion
How to Disable Double Click on the Header of a DataGridView
C# Execute SqlDataReader missing variable?
Web scraping: How to get specific element from some page?
aafdex-sdk unity3d crash on scene transition - only on Android

Categories

HOME
classification
twitter-bootstrap
blob
dynamic
readdir
sms
opengl-es
travis-ci-cli
gnuradio
sequence
samsung-gear-s2
rtc
ethereum
ng2-charts
comma
powerpivot
ibatis
geography
legend-properties
minimagick
cherrypy
android-navigation-drawer
oracle-golden-gate
chartist.js
mongoose-im
csproj
kundera
ng2-bootstrap
contextmenustrip
ports
eclipse-jdt
ansible-inventory
motherboard
latency
jslider
ape-phylo
inner-join
weld
line-endings
stream-socket-client
confluent
dotnet-cli
htop
kendo-scheduler
codesniffer
iban
sharing
blitz3d
portaudio
blackberry-webworks
distcc
mate-desktop
netlink
key-value-store
sprockets
patching
user-profile
periodic-processing
custom-build-step
alchemy
ewam
dynamics-nav
playn
gcc-warning
genero
google-experiments
xmla
alpha-beta-pruning
cordova-3
xmlserializer
formbuilder
redmine-plugins
powershell-v1.0
azure-worker-roles
android-relativelayout
sqldatasource
myrrix
grape-api
oc4j
wpa
uikit-dynamics
configurationsection
motordriver
unordered-set
stl-algorithm
discussion-board
cinder
azure-appfabric
miniport
mysql-pconnect
lts
jgrowl

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App