首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ToggleSwitch -如何启用文本?

ToggleSwitch -如何启用文本?
EN

Stack Overflow用户
提问于 2010-11-29 03:44:00
回答 1查看 973关注 0票数 1

我使用WP7控制工具包中的两个toggleSwitches,如下所示。根据第一个切换,应启用或禁用第二个切换开关。第二个切换开关的禁用正常工作,但当执行启用时,文本前景永远不会改变。请帮我弄清楚为什么会这样。

代码语言:javascript
复制
<!--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
}
EN

回答 1

Stack Overflow用户

发布于 2012-08-08 16:20:51

论“做”

代码语言:javascript
复制
toggleTwitterAutoPublish.IsChecked = false; 

(在AlterTwitterControlsDisplay函数的else部分),将触发设置isAutoPublish = falsetoggleTwitterAutoPublish_Unchecked

因此,下一次当您尝试

代码语言:javascript
复制
toggleTwitterAutoPublish.IsChecked = isAutoPublish;

这里的isAutoPublishfalse,因此你可能得不到想要的结果。

这就是我从你的问题中理解的。如果这不是问题,请解释清楚。希望这能有所帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4298659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档