[英]Adding CommandBar to top of current song list in xaml UWP. The property 'Content' is set more than once
I have two parts I'm trying to merge together xaml code, both work independently but when combined I can't get it to work.我有两个部分我正在尝试将 xaml 代码合并在一起,它们都独立工作,但是当结合起来我无法让它工作。 What's the right way.什么是正确的方法。 I've placed the CommandBar xmal just before the <GridView xaml.我已将 CommandBar xmal 放在 <GridView xaml 之前。 Thanks in advance for the beginner advice.提前感谢初学者的建议。
CommandBar XAML: to be displayed at the top of page enter image description here CommandBar XAML:显示在页面顶部 在此处输入图像描述
<CommandBar Margin="-10,46,10,0" IsOpen="True" Name="xCommand" >
<AppBarToggleButton x:Name="apbartg1" IsChecked="False" Icon="Mute" Label="Mute" Click="AppBarMuteButton_Click" />
<AppBarToggleButton Icon="RepeatAll" Label="Refresh" Click="AppBarRefreshButton_Click"/>
<AppBarSeparator/>
<AppBarButton Icon="Stop" Label="Stop" Click="AppBarStopButton_Click"/>
<AppBarButton Icon="Play" Label="Play" Click="AppBarPlayButton_Click"/>
<!--<CommandBar.SecondaryCommands>
<AppBarButton Icon="Like" Label="Like" Click="AppBarButton_Click"/>
<AppBarButton Icon="Dislike" Label="Dislike" Click="AppBarButton_Click"/>
</CommandBar.SecondaryCommands>-->
<CommandBar.Content>
<TextBlock x:Name="contentNameText" Text="Now playing..." Margin="12,8"/>
</CommandBar.Content>
</CommandBar>
List of Songs XAML: enter image description here歌曲列表 XAML:在此处输入图像描述
<Page
x:Class="mInc.WUP.Audio.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:mInc.WUP.Audio"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:mInc.WUP.Audio.Models"
mc:Ignorable="d">
<Page.Resources>
<x:String x:Key="ChevronGlyph"></x:String>
<CollectionViewSource
x:Name="GroupedMusicListSource"
Source="{x:Bind MainModel.GroupedMusicList}"
IsSourceGrouped="True"
ItemsPath="Items"
/>
<CollectionViewSource
x:Name="UngroupedMusicListSource"
Source="{x:Bind MainModel.UngroupedMusicList}"
IsSourceGrouped="False"
/>
</Page.Resources>
Placed the CommandBar Code Here and got the error.将 CommandBar 代码放在这里并得到错误。 I also tried other places but not able to find a solution.我也尝试了其他地方,但无法找到解决方案。
<GridView ItemsSource="{Binding Source={StaticResource GroupedMusicListSource}}"
SelectionMode="None"
Name="GuestGridView"
IsItemClickEnabled="True"
ItemClick="GuestGridView_ItemClick"
>
<GridView.GroupStyle >
<GroupStyle>
<GroupStyle.HeaderTemplate >
<DataTemplate x:DataType="models:SongGroupModel" >
<Grid Margin="0,0,0,2" >
<Button
Foreground="{ThemeResource ApplicationHeaderForegroundThemeBrush}"
IsEnabled="{x:Bind HasGroupDetails}"
Click="Header_Click"
Style="{StaticResource TextBlockButtonStyle}" >
<RelativePanel >
<TextBlock
Name="TitleBlock"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignVerticalCenterWithPanel="True"
Text="{x:Bind Title}" Margin="0,0,10,0"
Style="{StaticResource TitleTextBlockStyle}" />
<TextBlock
RelativePanel.RightOf="TitleBlock"
RelativePanel.AlignVerticalCenterWithPanel="True"
Text="{StaticResource ChevronGlyph}"
FontFamily="Segoe MDL2 Assets"
FontWeight="Normal"
Style="{StaticResource TitleTextBlockStyle}" />
</RelativePanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</GridView.GroupStyle>
<GridView.ItemTemplate>
<DataTemplate x:DataType="models:SongModel" >
<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Center"
Width="300"
BorderThickness="1" BorderBrush="DarkBlue"
Background="AliceBlue"
>
<StackPanel HorizontalAlignment="Center" Padding="5" >
<StackPanel Orientation="Horizontal" >
<TextBlock Text="Title:" FontWeight="Bold" />
<TextBlock Name="AlbumBlock" Margin="5,0,0,0"
Text="{x:Bind Title}" />
</StackPanel>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="Album:" FontWeight="Bold" />
<TextBlock Name="ArtistBlock" Margin="5,0,0,0"
Text="{x:Bind Album}" />
</StackPanel>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="Artist:" FontWeight="Bold" />
<TextBlock Name="TitleBlock" Margin="5,0,0,0"
Text="{x:Bind Artist}" />
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Page>
<Page.TopAppBar> <Page.TopAppBar>
<!--<CommandBar.SecondaryCommands>
<AppBarButton Icon="Like" Label="Like" Click="AppBarButton_Click"/>
<AppBarButton Icon="Dislike" Label="Dislike" Click="AppBarButton_Click"/>
</CommandBar.SecondaryCommands>-->
<CommandBar.Content>
<TextBlock x:Name="contentNameText" Text="Now playing..." Margin="12,8"/>
</CommandBar.Content>
</Page.TopAppBar> </Page.TopAppBar>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.