Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#360 Сделать кнопки в блоке заголовков как в мс сторе #361

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MusicX/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ResourceDictionary x:Name="ModalFrameStyles" Source="Styles/ModalFrameStyles.xaml" />
<ResourceDictionary x:Name="MusicXWindowStyles" Source="Styles/MusicXWindowStyles.xaml" />
<ResourceDictionary x:Name="LoadingBorderStyles" Source="Styles/LoadingBorderStyles.xaml" />
<ResourceDictionary x:Name="HyperlinkButtonStyles" Source="Styles/HyperlinkButtonStyles.xaml" />
</ResourceDictionary.MergedDictionaries>

<FontFamily x:Key="SegoeFluentIcons">pack://application:,,,/;component/Fonts/#Segoe Fluent Icons</FontFamily>
Expand Down
75 changes: 51 additions & 24 deletions MusicX/Controls/Blocks/TitleBlockControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,35 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wpfui="clr-namespace:Wpf.Ui.Controls;assembly=Wpf.Ui"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:models="clr-namespace:MusicX.Core.Models;assembly=MusicX.Core"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
mc:Ignorable="d"
d:DataContext="{d:DesignInstance models:Block}">
<UserControl.Resources>
<ControlTemplate x:Key="RegularTitleTemplate" TargetType="ContentControl">
<TextBlock
FontFamily="{StaticResource VKSansDemiBold}"
FontSize="30"
FontWeight="DemiBold"
Text="{TemplateBinding Content}" />
</ControlTemplate>
<ControlTemplate x:Key="ButtonTitleTemplate" TargetType="ContentControl">
<wpfui:HyperlinkButton
Style="{StaticResource HeaderHyperlinkButtonStyle}"
FontFamily="{StaticResource VKSansDemiBold}"
FontSize="30"
FontWeight="DemiBold"
Click="MoreButton_Click"
Content="{TemplateBinding Content}">
<wpfui:HyperlinkButton.Icon>
<wpfui:SymbolIcon Symbol="ChevronRight24" />
</wpfui:HyperlinkButton.Icon>
</wpfui:HyperlinkButton>
</ControlTemplate>
</UserControl.Resources>

<Grid
x:Name="TitleBlock"
Margin="0,0,0,13"
Expand All @@ -17,16 +43,29 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<StackPanel Grid.Column="0" VerticalAlignment="Top" Orientation="Horizontal">
<TextBlock
x:Name="Title"
VerticalAlignment="Center"
FontFamily="{StaticResource VKSansDemiBold}"
FontSize="30"
FontWeight="DemiBold"

Text="Title block" />
<ContentControl x:Name="Title" VerticalContentAlignment="Center">
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="Template" Value="{StaticResource RegularTitleTemplate}" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Actions.Count}" Value="1" />
<Condition Binding="{Binding Visibility, ElementName=ButtonsGrid}" Value="Collapsed" />
</MultiDataTrigger.Conditions>
<Setter Property="Template" Value="{StaticResource ButtonTitleTemplate}" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
<TextBlock
x:Name="BadgeHeader"
Grid.Column="0"
Expand All @@ -46,11 +85,12 @@

</StackPanel>

<TextBlock Margin="0,35,0,0" x:Name="Subtitle" Visibility="Collapsed" VerticalAlignment="Bottom" Opacity="0.4" Text="Subtitle"/>
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,5,0,0" x:Name="Subtitle" Visibility="Collapsed" VerticalAlignment="Bottom" Opacity="0.4" Text="Subtitle"/>

<Grid
x:Name="ButtonsGrid"
Grid.Column="2"
Grid.Row="0" Grid.Column="2"
Grid.RowSpan="2"
Width="170"
Height="30"
Margin="0,0,5,0"
Expand All @@ -74,18 +114,5 @@

</Grid>


<wpfui:Button
x:Name="MoreButton"
Grid.Column="1"
Height="30"
Margin="0,0,0,0"
Padding="8 0"
HorizontalAlignment="Right"
Appearance="Secondary"
Click="MoreButton_Click"
FontFamily="{StaticResource VKSansDemiBold}"
Visibility="Collapsed" />

</Grid>
</UserControl>
48 changes: 13 additions & 35 deletions MusicX/Controls/Blocks/TitleBlockControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ private void TitleBlockControl_Loaded(object sender, DependencyPropertyChangedEv
Title.FontSize = 15;
}

Title.Text = block.Layout.Title;
Title.Content = block.Layout.Title;

if(block.Layout.TopTitle is not null || block.Layout.Subtitle is not null)
{
Subtitle.Text = block.Layout.TopTitle?.Text ?? block.Layout.Subtitle;
Subtitle.Visibility = Visibility.Visible;
if (block.Actions.Count == 1)
Subtitle.Margin = new(11, 0, 11, 0);
}

if (block.Badge != null)
Expand All @@ -58,62 +60,38 @@ private void TitleBlockControl_Loaded(object sender, DependencyPropertyChangedEv
BadgeHeader.Visibility = Visibility.Visible;
}

if (block.Buttons != null && block.Buttons.Count > 0) //ios
if (block.Buttons is { Count: > 0 }) //ios
{
if (block.Buttons[0].Options.Count > 0)
{
ButtonsGrid.Visibility = Visibility.Visible;
TitleButtons.Text = block.Buttons[0].Title;
Buttons.Visibility = Visibility.Visible;
MoreButton.Visibility = Visibility.Collapsed;
foreach (var option in block.Buttons[0].Options)
{
Buttons.Items.Add(new TextBlock() { Text = option.Text });
}
//Buttons.SelectedIndex = 0;
return;
}
else
{
MoreButton.Visibility = Visibility.Visible;

MoreButton.Content = block.Buttons[0].Title;

return;

}
}
else
{

if(block.Actions.Count > 0)
if(block.Actions.Count > 0 && block.Actions[0].Options.Count > 0)
{

if (block.Actions[0].Options.Count > 0) //android
{
ButtonsGrid.Visibility = Visibility.Visible;
TitleButtons.Text = block.Actions[0].Title;
Buttons.Visibility = Visibility.Visible;
MoreButton.Visibility = Visibility.Collapsed;
//android
ButtonsGrid.Visibility = Visibility.Visible;
TitleButtons.Text = block.Actions[0].Title;
Buttons.Visibility = Visibility.Visible;


foreach (var option in block.Actions[0].Options)
{
Buttons.Items.Add(new TextBlock() { Text = option.Text });
}

return;
}
else
foreach (var option in block.Actions[0].Options)
{
MoreButton.Visibility = Visibility.Visible;

MoreButton.Content = block.Actions[0].Title;

return;

Buttons.Items.Add(new TextBlock() { Text = option.Text });
}


return;
}

return;
Expand Down
109 changes: 109 additions & 0 deletions MusicX/Styles/HyperlinkButtonStyles.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="http://schemas.lepo.co/wpfui/2022/xaml">
<Thickness x:Key="HeaderHyperlinkButtonIconMargin">0,5,0,0</Thickness>

<Style x:Key="HeaderHyperlinkButtonStyle" TargetType="{x:Type controls:HyperlinkButton}">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<Setter Property="Background" Value="{DynamicResource HyperlinkButtonBackground}" />
<Setter Property="Foreground" Value="{DynamicResource HyperlinkButtonForeground}" />
<Setter Property="BorderThickness" Value="{StaticResource HyperlinkButtonBorderThemeThickness}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Padding" Value="{StaticResource HyperlinkButtonPadding}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="Appearance" Value="Secondary" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:HyperlinkButton}">
<Border
x:Name="ContentBorder"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Padding="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<ContentPresenter
x:Name="ContentPresenter"
Grid.Column="0"
Content="{TemplateBinding Content}"
TextElement.Foreground="{TemplateBinding Foreground}" />

<ContentControl
x:Name="ControlIcon"
Grid.Column="1"
Margin="{StaticResource HeaderHyperlinkButtonIconMargin}"
VerticalAlignment="Center"
Content="{TemplateBinding Icon}"
Focusable="False"
Foreground="{TemplateBinding Foreground}" />
</Grid>
</Border>
<ControlTemplate.Resources>
<Storyboard x:Key="HyperlinkButtonBackgroundPointerOverStart">
<ThicknessAnimation To="6,0,0,0" Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Margin" Duration="0:0:.16" />
</Storyboard>
<Storyboard x:Key="HyperlinkButtonBackgroundPointerOverEnd">
<ThicknessAnimation To="0" Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Margin" Duration="0:0:.16" />
</Storyboard>
</ControlTemplate.Resources>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsPressed" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource HyperlinkButtonBackgroundPointerOver}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource HyperlinkButtonForegroundPointerOver}" />
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource HyperlinkButtonBackgroundPointerOverStart}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource HyperlinkButtonBackgroundPointerOverEnd}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsPressed" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource HyperlinkButtonBackgroundPressed}" />
<Setter TargetName="ControlIcon" Property="Foreground" Value="{DynamicResource HyperlinkButtonForegroundPressed}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource HyperlinkButtonForegroundPressed}" />
</MultiTrigger>
<Trigger Property="Icon" Value="{x:Null}">
<Setter TargetName="ControlIcon" Property="Margin" Value="0" />
<Setter TargetName="ControlIcon" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource HyperlinkButtonBackgroundDisabled}" />
<Setter TargetName="ControlIcon" Property="Foreground" Value="{DynamicResource HyperlinkButtonForegroundDisabled}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource HyperlinkButtonForegroundDisabled}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>