0

我正在尝试将 XML 页面绑定到相同的底层代码页。

<toolkit:ToggleSwitch Foreground="Transparent" Checked="ToggleSwitch_Checked" IsChecked="{Binding Source={StaticResource appSettings}, Path=LockSetting, Mode=TwoWay}">
    <toolkit:ToggleSwitch.ContentTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical" DataContext="{Binding}">
                <TextBlock Text="locks or unlocks your calender" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="statusBox" Text="{Binding stat1}" Style="{StaticResource PhoneTextTitle3Style}" />
            </StackPanel>
        </DataTemplate>
    </toolkit:ToggleSwitch.ContentTemplate>

我已将数据上下文设置为

stat1 = "abn";
InitializeComponent();

aps = this.Resources["appSettings"] as AppSettings;
this.colorpicker.Color = Color.FromArgb(aps.ASetting, aps.RSetting, aps.GSetting, aps.BSetting);
ContentPanel.DataContext = this;

但这根本行不通。任何帮助都会很好。

4

1 回答 1

1

当您编写ContentPanel.DataContext = this它时,这意味着在这种情况下 XAML 的代码隐藏将为数据绑定提供上下文。更具体地说,当您{Binding sta1}在 XAML 中编写时,sta1 必须是后面代码中的属性。也就是说, sta1 应该是这样的:

public String sta1 { get; set; }
于 2012-08-13T11:57:56.807 回答