0

プロジェクトでリストを作成していますが、各項目にボタンが必要です。

Windows phone の「最終通話」ページのように、ListBox でこれらのボタンを取得するにはどうすればよいですか?

ありがとう。

4

4 に答える 4

2

FunksMaNameの答えは、小さな変更を除いて非常に正しいです.....

<ListBox Height="360"
          HorizontalAlignment="Left"
          Margin="22,23,0,0"
          Name="UserDetailsListBox"
          VerticalAlignment="Top"
          Width="413">  <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                 <Button.Template>
                        <ControlTemplate>
                          <Image Source="/Assets/Images/MyImage.png" />
                        </ControlTemplate>
                    </Button.Template>
               <TextBlock x:Name="txtOverViewHeader1"
                          Text="OverView"
                          Foreground="Yellow"
                          Width="600"
                          FontSize="28"
                          Margin="10,0,0,0"
                          Height="65">
                </TextBlock>
             </StackPanel>
        </DataTemplate></ListBox.ItemTemplate></ListBox>

コンテンツではなくボタンのテンプレート内に画像を移動しただけです...それはより正確です..

于 2013-09-05T12:49:55.273 に答える
1

このように、リストボックスの各項目にボタンを追加できます。

<ListBox Height="360"
                  HorizontalAlignment="Left"
                  Margin="22,23,0,0"
                  Name="UserDetailsListBox"
                  VerticalAlignment="Top"
                  Width="413">
 <ListBox.ItemTemplate>
                <DataTemplate>
                   <StackPanel Orientation="Vertical"
                               >
    <StackPanel Orientation="Horizontal">
                        <Button Width="150" Height="50" x:Name="Btn1" Content="Button1"                                 Margin="0,-20,0,0"/>
                       <TextBlock x:Name="txtOverViewHeader1"
                                  Text="OverView"
                                  Foreground="Yellow"
                                  Width="600"
                                  FontSize="28"
                                  Margin="10,0,0,0"
                                  Height="65">
                        </TextBlock>
                     </StackPanel>

             <StackPanel Orientation="Horizontal">
                        <Button Width="150" Height="50" x:Name="Btn2" Content="Button2"                                 Margin="0,-20,0,0"/>
                       <TextBlock x:Name="txtOverViewHeader2"
                                  Text="OverView"
                                  Foreground="Yellow"
                                  Width="600"
                                  FontSize="28"
                                  Margin="10,0,0,0"
                                  Height="65">
                        </TextBlock>
                     </StackPanel>

                </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>

                </ListBox>

それがあなたに望ましい答えを与えることを願っています

于 2013-09-05T12:00:41.947 に答える