Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Items控件内的访问按钮_C#_Xaml_Windows Runtime_Windows Store - Fatal编程技术网

C# Items控件内的访问按钮

C# Items控件内的访问按钮,c#,xaml,windows-runtime,windows-store,C#,Xaml,Windows Runtime,Windows Store,我在windows应用商店项目中有此代码 <ItemsControl Name="ItemStuff"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"></StackPanel>

我在windows应用商店项目中有此代码

            <ItemsControl Name="ItemStuff">
              <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"></StackPanel>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                      <TextBlock Text="lala" Foreground="White" Tapped="SomeFunc"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

我将ItemsControl的items.source设置为包含6项的列表,
当我点击textblock时,我将文本的前景色更改为红色,但我想将其他按钮设置为白色,我如何从点击的事件函数访问其他按钮,以便当我按下第三项的文本时,第一项已为红色,它将第三个变为红色,第一个变为白色。

您可以使用
ListBox
代替
ItemsControl
,因为它提供了选择功能并更改
ListBoxItem.Template
,当选择它时,它将变为
Background
红色



现在停下来学习MVVM。在没有MVVM的情况下使用XAML非常痛苦。我想访问函数中的6个TextBlock控件,不知道这与MVVM有什么关系。如果使用MVVM,就不会有这个问题。@Ric,为什么不使用单选的
ListBox
?我需要将标题(TexBlocks中的文本)并排放置,我可以用ListBox吗?