ToggleSwitch - how to enable text?
I am using two toggleSwitches as below from the WP7 control toolkit. Based on the first toggle, the second toggle switch should be enabled or disabled. The disable of the second toggle switch works fine but when the enable is performed, the text foreground is never changed. Please help me figure out why this is happening.
<!--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:ToggleSwi开发者_StackOverflow社区tch.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
}
On doing
toggleTwitterAutoPublish.IsChecked = false;
(in AlterTwitterControlsDisplay function's else part), the toggleTwitterAutoPublish_Unchecked
is triggered which sets isAutoPublish = false
hence next time when you try to do
toggleTwitterAutoPublish.IsChecked = isAutoPublish;
here isAutoPublish
is false
hence you may not get the desired result.
That is what I have understood from your question. If this was not the problem please explain it clearly. Hope this helps
精彩评论