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

Is there a LINQ Query Provider for querying C# files?
trying to redirect after login
Unable to Registering dll at new path in dev machine
SurfaceImageSource and IDXGISurface BackBuffer size mismatch
Game of Life - What is with this algorithm
Parse JSON text file using C#
WPF: How to Assign data to the DataContext of a Control that is Located in Windows.Resources?
Facebook OAuth redirect_uri isn't an absolute URI. Check RFC 3986.\“,\”type\“:\”OAuthException\“,\”code\":191
MVC Model Binding List of objects
PictureBox Is Nowhere To Be Seen
using types from dll A in dll B
Modifying string.Substring
Getting information out of a listbox windows phone 8
What is a ListBox' DrawItem
Place a normal ProgressBar to the exact location of a ToolStripProgressBar
How to continue standart Asp.net Mvc - Application Error Page

Categories

HOME
joomla
oop
gcc
optimization
mobile
salesforce
ssh
cluster-analysis
phantomjs
nagios
stdout
itext7
sms
opengl-es
download
powerquery
wkhtmltopdf
digital
email-attachments
element
hql
box2d
powerpivot
gomobile
git-branch
angular2-pipe
inline-assembly
datastax-enterprise
core-animation
csproj
ipython-parallel
openoffice-impress
spring-oauth2
unity3d-5
javax
sampling
flex3
maven-2
const
armadillo
aspose.pdf
keychain
definition
colorbox
piranha-cms
android-doze-and-standby
monaca
jcs
appcmd
sharpssh
seyren
node.js-client
vertex-shader
fileopendialog
strtol
alfred
tinybox2
system-integration
boost-bind
containstable
dday
videoview
gtkwave
first-order-logic
roslyn-code-analysis
winforms-interop
android-filterable
eula
web-standards
teamwork
alpha-beta-pruning
parallel-port
sqldatasource
data-layers
nativequery
xcode6.1-gm-seed
complete
xml-validation
thucydides
google-oauth-java-client
pechkin
nsnumber
xrandr
backbone-views
google-checkout
uikit-dynamics
phone-state-listener
event-propagation
erlide
motorola-droid
advanceddatagrid
pinchzoom
jquery-click-event
moss2007-security
conditional-operator
carbon-emacs
scala-designer

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