Skip to content

Commit f926c76

Browse files
committed
🎨 增加导航条按键
1 parent 20650b2 commit f926c76

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/Avalonia.WebView2.Sample.Mobile/Views/MainView.axaml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,50 @@
1919
</Design.DataContext>
2020

2121
<DockPanel>
22-
<TextBox
23-
x:Name="UrlTextBox"
22+
<Grid
2423
Margin="{Binding StatusBarMargin}"
25-
DockPanel.Dock="Top"
26-
Watermark="Enter the HTTPS address, then press the Enter key to navigate." />
24+
ColumnDefinitions="auto, auto, auto, *"
25+
DockPanel.Dock="Top">
26+
<Button
27+
x:Name="GoBackButton"
28+
Grid.Column="0"
29+
IsEnabled="{Binding CanGoBack, ElementName=WV}">
30+
<TextBlock Text="&#x2190;">
31+
<TextBlock.RenderTransform>
32+
<TransformGroup>
33+
<ScaleTransform ScaleX="2" ScaleY="2" />
34+
<TranslateTransform Y="-2" />
35+
</TransformGroup>
36+
</TextBlock.RenderTransform>
37+
</TextBlock>
38+
</Button>
39+
<Button x:Name="GoForwardButton" Grid.Column="1">
40+
<TextBlock Text="&#x2192;">
41+
<TextBlock.RenderTransform>
42+
<TransformGroup>
43+
<ScaleTransform ScaleX="2" ScaleY="2" />
44+
<TranslateTransform Y="-2" />
45+
</TransformGroup>
46+
</TextBlock.RenderTransform>
47+
</TextBlock>
48+
</Button>
49+
<Button x:Name="Refresh" Grid.Column="2">
50+
<TextBlock Text="&#x21BB;">
51+
<TextBlock.RenderTransform>
52+
<TransformGroup>
53+
<ScaleTransform ScaleX="2" ScaleY="2" />
54+
<TranslateTransform Y="-2" />
55+
</TransformGroup>
56+
</TextBlock.RenderTransform>
57+
</TextBlock>
58+
</Button>
59+
60+
<TextBox
61+
x:Name="UrlTextBox"
62+
Grid.Column="3"
63+
Watermark="Enter the HTTPS address, then press the Enter key to navigate." />
64+
</Grid>
65+
2766
<wv2:WebView2
2867
x:Name="WV"
2968
DockPanel.Dock="Bottom"

src/Avalonia.WebView2.Sample.Mobile/Views/MainView.axaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ public MainView()
1818

1919
WV.StorageService = this;
2020
//WV.Fill = new SolidColorBrush(Colors.Purple);
21+
22+
GoBackButton.Click += (s, e) =>
23+
{
24+
if (WV.CanGoBack)
25+
{
26+
WV.GoBack();
27+
}
28+
};
29+
GoForwardButton.Click += (s, e) =>
30+
{
31+
if (WV.CanGoForward)
32+
{
33+
WV.GoForward();
34+
}
35+
};
36+
Refresh.Click += (s, e) => WV.Reload();
2137
}
2238

2339
IEnumerable<KeyValuePair<(StorageItemType type, string key), StorageItemValue>>? IStorageService.GetStorages(string requestUri)

0 commit comments

Comments
 (0)