確定相當簡單,我的頁面上有一個ToggleSwitch,就像這樣。xaml Twoway綁定到PhoneApplicationPage代碼中的一個屬性
<toolkit:ToggleSwitch x:Name="togLocation" VerticalAlignment="Center"
Style="{StaticResource gToggleSwitchStyle}" Foreground="{StaticResource brLightFont}"
Loaded="togLocation_Loaded" IsChecked="{Binding LocationTrackingEnabled, Mode=TwoWay}"/>
在同一頁面背後的代碼
我有以下
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
正如你所看到的默認值是假的,因此toggleswitch.IsChecked應該是假的。不是它的真實。使用斷點我檢查LocationTrackingEnabled,它永遠不會變得如此清楚綁定不起作用。
我已經在後面的代碼中試過了。
DataContext = this;
我也曾在頁面
DataContext="{Binding RelativeSource={RelativeSource Self}}"
之前,我已經做了綁定的XAML試過,但我看不到的問題。
「LocationTrackingEnabled」屬性的父類是什麼? –
其PhoneApplicationPage。所以基本上,頁面上的切換開關綁定到在 – Gaz83