ok fairly simple, I have a ToggleSwitch on my page like so.
<toolkit:ToggleSwitch x:Name="togLocation" VerticalAlignment="Center"
Style="{StaticResource gToggleSwitchStyle}" Foreground="{StaticResource brLightFont}"
Loaded="togLocation_Loaded" IsChecked="{Binding LocationTrackingEnabled, Mode=TwoWay}"/>
in the code behind of the same page I have the following
public partial class Setup : PhoneApplicationPage
{
public bool LocationTrackingEnabled
{
get { return (bool)GetValue(LocationTrackingEnabledProperty); }
set
{
SetValue(LocationTrackingEnabledProperty, value);
}
}
public static readonly DependencyProperty LocationTrackingEnabledProperty =
DependencyProperty.Register("LocationTrackingEnabled",
typeof(bool),
typeof(Setup),
new PropertyMetadata(false));
// blah blah rest of the page code follows on
as you can see the default value is false so the toggleswitch.IsChecked should be false. Nope its true. Using breakpoint I check LocationTrackingEnabled and it never changes so clearly the binding does no work.
I have tried this in code behind.
DataContext = this;
I have also tried this in the xaml of the page
DataContext="{Binding RelativeSource={RelativeSource Self}}"
I have done bindings before but I can't see the issue.
There's no need for this to be a DependencyProperty. Just use it as a regular property. Also, check your debug output when you run-- if you have a binding issue, it will show up there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.