我使用WP7控制工具包中的两个toggleSwitches,如下所示。根据第一个切换,应启用或禁用第二个切换开关。第二个切换开关的禁用正常工作,但当执行启用时,文本前景永远不会改变。请帮我弄清楚为什么会这样。
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:ToggleSwitch Header="twitter" Margin="10,15,0,0" Name="toggleTwitter" Checked="toggleTwitter_Checked" Unchecked="toggleTwitter_Unchecked">
<toolkit:ToggleSwitch.HeaderTemplate>
<DataTemplate>
<ContentControl FontSize="{StaticResource PhoneFontSizeLarge}" Foreground="{StaticResource PhoneForegroundBrush}" Content="{Binding}"/>
</DataTemplate>
</toolkit:ToggleSwitch.HeaderTemplate>
<toolkit:ToggleSwitch.ContentTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Status: " FontSize="{StaticResource PhoneFontSizeMedium}"/>
<ContentControl HorizontalAlignment="Left" FontSize="{StaticResource PhoneFontSizeMedium}" Content="{Binding}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</toolkit:ToggleSwitch.ContentTemplate>
</toolkit:ToggleSwitch>
<toolkit:ToggleSwitch Header="" Margin="10,100,0,-35" Name="toggleTwitterAutoPublish" Checked="toggleTwitterAutoPublish_Checked" Unchecked="toggleTwitterAutoPublish_Unchecked">
<toolkit:ToggleSwitch.ContentTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Auto Publish: " FontSize="{StaticResource PhoneFontSizeMedium}" Margin="0,-15,0,0" />
<ContentControl HorizontalAlignment="Left" FontSize="{StaticResource PhoneFontSizeMedium}" Content="{Binding}" IsEnabled="{Binding}" Margin="0,-15,0,0"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</toolkit:ToggleSwitch.ContentTemplate>
</toolkit:ToggleSwitch>
</Grid>
public partial class MainPage : PhoneApplicationPage
{
bool isConnected = false;
bool isAutoPublish = false;
public const string SIGNED_IN_MESSAGE = "Signed In";
public const string SIGNED_OUT_MESSAGE = "Signed Out";
// Constructor
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
toggleTwitter.IsChecked = isConnected;
AlterTwitterControlsDisplay();
base.OnNavigatedTo(e);
}
#region Twitter
private void AlterTwitterControlsDisplay()
{
if (toggleTwitter.IsChecked.Value)
{
toggleTwitter.Content = SIGNED_IN_MESSAGE;
toggleTwitterAutoPublish.IsEnabled = true;
toggleTwitterAutoPublish.IsChecked = isAutoPublish;
}
else
{
toggleTwitter.Content = SIGNED_OUT_MESSAGE;
toggleTwitterAutoPublish.IsEnabled = false;
toggleTwitterAutoPublish.IsChecked = false;
}
}
private void toggleTwitter_Checked(object sender, RoutedEventArgs e)
{
isConnected = true;
AlterTwitterControlsDisplay();
}
private void toggleTwitter_Unchecked(object sender, RoutedEventArgs e)
{
isConnected = false;
AlterTwitterControlsDisplay();
}
private void toggleTwitterAutoPublish_Checked(object sender, RoutedEventArgs e)
{
isAutoPublish = true;
}
private void toggleTwitterAutoPublish_Unchecked(object sender, RoutedEventArgs e)
{
isAutoPublish = false;
}
#endregion Twitter
}发布于 2012-08-08 16:20:51
论“做”
toggleTwitterAutoPublish.IsChecked = false; (在AlterTwitterControlsDisplay函数的else部分),将触发设置isAutoPublish = false的toggleTwitterAutoPublish_Unchecked
因此,下一次当您尝试
toggleTwitterAutoPublish.IsChecked = isAutoPublish;这里的isAutoPublish是false,因此你可能得不到想要的结果。
这就是我从你的问题中理解的。如果这不是问题,请解释清楚。希望这能有所帮助
https://stackoverflow.com/questions/4298659
复制相似问题