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

标题栏样式修改 #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
258 changes: 258 additions & 0 deletions HomePage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
<Page
x:Class="Webbrowser_winui3.Views.HomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:Webbrowser_winui3.Models"
xmlns:xaml="using:Microsoft.UI.Xaml"
mc:Ignorable="d">
<Page.Resources>
<Style x:Key="NoBlueUnderlineTextBoxStyle" TargetType="TextBox">
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
<Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
<Setter Property="Foreground" Value="{ThemeResource TextControlForeground}" />
<Setter Property="Background" Value="{ThemeResource TextControlBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}" />
<Setter Property="SelectionHighlightColor" Value="{ThemeResource TextControlSelectionHighlightColor}" />
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<Border
x:Name="BorderElement"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<ScrollViewer
x:Name="ContentElement"
Padding="{TemplateBinding Padding}"
AutomationProperties.AccessibilityView="Raw"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
IsTabStop="False"
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
ZoomMode="Disabled" />
<TextBlock
x:Name="PlaceholderTextContentPresenter"
Padding="{TemplateBinding Padding}"
Foreground="{TemplateBinding PlaceholderForeground}"
IsHitTestVisible="False"
Text="{TemplateBinding PlaceholderText}" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Target="PlaceholderTextContentPresenter.Foreground" Value="Transparent" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="NoBlueUnderlineTextBoxStyle2" TargetType="TextBox">
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
<Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
<Setter Property="Foreground" Value="{ThemeResource TextControlForeground}" />
<Setter Property="Background" Value="{ThemeResource TextControlBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}" />
<Setter Property="SelectionHighlightColor" Value="{ThemeResource TextControlSelectionHighlightColor}" />
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Target="PlaceholderTextContentPresenter.Foreground" Value="Transparent" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="BorderElement" Background="Transparent" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" />
<ScrollViewer x:Name="ContentElement" AutomationProperties.AccessibilityView="Raw" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" IsTabStop="False" Padding="{TemplateBinding Padding}" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" ZoomMode="Disabled" VerticalContentAlignment="Center" />
<TextBlock x:Name="PlaceholderTextContentPresenter" Foreground="{TemplateBinding PlaceholderForeground}" Padding="{TemplateBinding Padding}" IsHitTestVisible="False" Text="{TemplateBinding PlaceholderText}" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid x:Name="root">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid
Grid.Row="0"
Height="40"
VerticalAlignment="Top"
Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Button
Background="Transparent"
BorderThickness="0"
Content="&#xE112;"
FontFamily="Segoe MDL2 Assets" />
<Button
Background="Transparent"
BorderThickness="0"
Content="&#xE111;"
FontFamily="Segoe MDL2 Assets" />
<Button
Background="Transparent"
BorderThickness="0"
Content="&#xE149;"
FontFamily="Segoe MDL2 Assets" />
<TextBlock
Margin="5,0,5,2"
VerticalAlignment="Center"
Text="|" />
</StackPanel>
<TextBox
x:Name="tb_url"
Grid.Column="1"
Height="30"
Padding="3"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
x:FieldModifier="public"
AutomationProperties.AccessibilityView="Raw"
Background="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}"
BorderThickness="0"
FocusVisualMargin="-3"
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
GotFocus="{x:Bind listDetailsViewModel.tb_url_GotFocus}"
IsTabStop="True"
KeyUp="{x:Bind listDetailsViewModel.tb_url_KeyUp}"
PlaceholderForeground="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}"
PointerEntered="TextBox_PointerEntered"
PointerExited="TextBox_PointerExited"
PointerPressed="TextBox_PointerPressed"
PointerReleased="TextBox_PointerReleased"
SelectionHighlightColor="{x:Null}"
Style="{StaticResource NoBlueUnderlineTextBoxStyle2}"
Text="app://home/" />

<StackPanel Grid.Column="2" Orientation="Horizontal">
<Button
Background="Transparent"
BorderThickness="0"
Click="GobnClick"
Content="&#xE111;"
FontFamily="Segoe MDL2 Assets" />
<Button
Background="Transparent"
BorderThickness="0"
Click="{x:Bind listDetailsViewModel.ButtonAddToHome_Click}"
Content="&#xE10F;"
FontFamily="Segoe MDL2 Assets"
Tag="{x:Bind tb_url.Text, Mode=OneWay}" />
<Button
Background="Transparent"
BorderThickness="0"
Content="&#xE113;"
FontFamily="Segoe MDL2 Assets" />
<Button
Background="Transparent"
BorderThickness="0"
Click="{x:Bind listDetailsViewModel.FavButton_Click}"
Content="&#xE1CE;"
FontFamily="Segoe MDL2 Assets" />
<Button
Background="Transparent"
BorderThickness="0"
Click="{x:Bind listDetailsViewModel.HisButton_Click}"
Content="&#xE1A2;"
FontFamily="Segoe MDL2 Assets" />
<Button
Background="Transparent"
BorderThickness="0"
Content="&#xE118;"
FontFamily="Segoe MDL2 Assets" />
<Button
Background="Transparent"
BorderThickness="0"
Click="{x:Bind listDetailsViewModel.MoreButton_Click}"
Content="&#xE115;"
FontFamily="Segoe MDL2 Assets" />
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<Grid
Margin="160,100,160,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<TextBox
x:Name="tb_homeurl"
Height="35"
Margin="0,0,40,0"
HorizontalAlignment="Stretch"
KeyUp="TextBox_KeyUp" />
<Button
HorizontalAlignment="Right"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Click="Button_Click"
Content="&#xE111;"
FontFamily="Segoe MDL2 Assets" />
</Grid>
<ScrollViewer Margin="140,160,140,100">
<GridView x:Name="gv">
<GridView.ItemTemplate>
<DataTemplate x:DataType="models:WebModel">
<Grid
Width="120"
Height="90"
Margin="0,10,0,10"
Background="#01ffffff"
Holding="Grid_Holding"
PointerPressed="Grid_PointerPressed"
RightTapped="Grid_RightTapped"
Tag="{x:Bind Url, Mode=OneWay}">
<Image
Width="50"
Height="50"
Margin="0,10,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Source="{x:Bind tabItemIcon, Mode=OneWay}" />
<TextBlock
Margin="10,0,10,5"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
FontSize="12"
FontWeight="Normal"
Text="{x:Bind SimpleTitle, Mode=OneWay}"
TextWrapping="NoWrap" />
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</ScrollViewer>
</Grid>
</Grid>
</Grid>
</Page>
82 changes: 82 additions & 0 deletions HomePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Webbrowser_winui3.Models;
using Webbrowser_winui3.Services;
using Webbrowser_winui3.ViewModels;
using Windows.Devices.Enumeration;

namespace Webbrowser_winui3.Views;

// TODO: Set the URL for your privacy policy by updating SettingsPage_PrivacyTermsLink.NavigateUri in Resources.resw.
public sealed partial class HomePage : Page
{
ListDetailsViewModel listDetailsViewModel = new ListDetailsViewModel();
public HomePage()
{
InitializeComponent();
this.Loaded += (s, e) =>
{
HomePageViewModel.InitCommand.Execute(gv);
};
}
private void GobnClick(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
MainViewModel.OpenWebPageCommand.Execute(tb_url.Text);
}


private void Grid_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
var properties = e.GetCurrentPoint(root).Properties;
if (properties.IsLeftButtonPressed)
{
HomePageViewModel.gv_ItemClickCommand.Execute(sender as Grid);
}
}

private void TextBox_KeyUp(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
MainViewModel.OpenWebPageCommand.Execute(tb_homeurl.Text);
}
}

private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
MainViewModel.OpenWebPageCommand.Execute(tb_homeurl.Text);
}

private void Grid_Holding(object sender, Microsoft.UI.Xaml.Input.HoldingRoutedEventArgs e)
{
HomePageViewModel.RightMenuCommand.Execute(sender as Grid);
}

private void Grid_RightTapped(object sender, Microsoft.UI.Xaml.Input.RightTappedRoutedEventArgs e)
{
HomePageViewModel.RightMenuCommand.Execute(sender as Grid);
}

private void TextBox_PointerPressed(object sender, PointerRoutedEventArgs e)
{
TextBox textBox = sender as TextBox;
textBox.Background = textBox.Background;
}

private void TextBox_PointerReleased(object sender, PointerRoutedEventArgs e)
{
TextBox textBox = sender as TextBox;
textBox.Background = textBox.Background;
}

private void TextBox_PointerExited(object sender, PointerRoutedEventArgs e)
{
TextBox textBox = sender as TextBox;
textBox.Background = textBox.Background;
}
private void TextBox_PointerEntered(object sender, PointerRoutedEventArgs e)
{
TextBox textBox = sender as TextBox;
textBox.Background = textBox.Background;
}
}
Loading