0

我是windows phone 8开发的初学者,我需要创建一个标签系统(有点像Android上的slidingDrawer)。我解释一下自己,我已经实现了一个 xaml 接口,它看起来像这样:

http://img15.hostingpics.net/pics/974529onglet.png

这个接口的代码:

<StackPanel  VerticalAlignment="top" Orientation="Horizontal" Height="402" Width="480">
            <StackPanel Width="161" Margin="0,10,0,0" >
                <StackPanel Height="50" Background="DarkCyan">
                    <TextBlock Height="50" Text="Qualité orale" Foreground="White"  />
                </StackPanel>
                <StackPanel Height="50" >

                    <TextBlock Text="Compréhension" Foreground="White" />
                </StackPanel>
                <StackPanel Height="50">
                    <TextBlock Text="Général" Foreground="White"/>
                </StackPanel>
                <StackPanel Height="50">
                    <TextBlock Text="Fichiers relatifs" Foreground="White"/>
                </StackPanel>
                <StackPanel Height="50">
                    <TextBlock Text="Le conférencier" Foreground="White"/>
                </StackPanel>
                <StackPanel Height="50">
                    <TextBlock Text="Questions" Foreground="White"/>
                </StackPanel>

            </StackPanel>

我在这里想要做的是,当用户触摸堆栈面板时,堆栈面板会改变他的颜色,右侧的灰色内容也会改变。

你能帮我解决我的问题吗?

先感谢您

4

2 回答 2

0

只需将 Tap 属性添加到 TextBlocks 并处理来自后面代码的事件。

例如:

<TextBlock Text="Questions" 
           Foreground="White"
           Tap="MyEventHandler"
/>

然后,您需要为 StackPanels 提供 Name 属性,以便您可以在代码中引用它。像这样:

<StackPanel Height="50" Name="QuestionsStackPanel">
       <TextBlock Text="Questions" Foreground="White"/>
</StackPanel>

在文件后面的代码中,Visual Studio 可能会自动生成方法存根,如果不是,它应该看起来像这样。

private void MyEventHandler(object sender, System.Windows.Input.GestureEventArgs e)
{
     //Make changes here
     QuestionsStackPanel.Background = Colors.Blue
}

从这里您可以更改您提到的特定选项卡和灰色区域的颜色。

于 2013-08-21T08:46:58.327 回答
0

首先,仅供参考,“android tabs 界面”与“UI (metro)”界面不一致。这不是很重要,有关“UI 设计风格”的更多信息,您可以在此处为您的应用设置样式:d

对于您的问题,在您的 Xaml 中,您可以添加一个事件以检测点击(或“TextBlock”中的其他事件。

例如,您可以在“Code.xaml”中的所有按钮中添加一个“Tap Event”(此外,您可以添加一个“Name”属性以便在之后轻松查找您的控件):

<StackPanel  VerticalAlignment="top" Orientation="Horizontal" Height="402" Width="480">
    <StackPanel Name ="Global_Onglets" Width="161" Margin="0,10,0,0" >
        <StackPanel Height="50" Background="DarkCyan">
            <TextBlock Height="50" 
                       Text="Qualité orale" 
                       Name="TextBlock_Quality"
                       Tap="MyPersonalEvent"
                       Foreground="White"  />
        </StackPanel>
        <StackPanel Height="50" >
            <TextBlock Text="Compréhension" 
                       Name="TextBlock_Comprehension"
                       Tap="MyPersonalEvent"
                       Foreground="White" />
        </StackPanel>
        <StackPanel Height="50">
            <TextBlock Text="Général" 
                       Name="TextBlock_General"
                       Tap="MyPersonalEvent"
                       Foreground="White"/>
        </StackPanel>
    </StackPanel>
</StackPanel>

并且,在您的“code.cs”中,您创建了您的事件方法:

/// <summary>
/// Event handler called by Textblock Tap.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyPersonalEvent(object sender, EventArgs e)
{
    // Get, the current textblock where called the event.
    TextBlock CurrentTextBlock = sender as TextBlock;

    // Check just the clicked textBlock, for attributes specific colors..
    foreach (TextBlock textblock in Global_Onglets.Children)
    {
        if (textblock == sender)
        {
            // Attribute secific color for this tap textblock;

        }
       // Attribute a "normal" color for alls others textBlock..
    }
}

您可以在此处了解有关活动的更多详细信息!

另外,我看到你用法语创建了你的应用程序。但是,如果你想在这里有一个关于“本地化你的应用程序”的很棒的教程,你可以很容易地本地化你的应用程序,以便用其他语言在此处创建(并在其他国家/地区分发……)……最好事先考虑一下,任何职责稍后再试。:D

于 2013-08-21T09:09:21.483 回答