Skip to content

Commit 18bb494

Browse files
committed
#165: Add bindings for SetZoomLevel in WinForms
1 parent 3dad4cc commit 18bb494

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

CefSharp.Wpf.Example/MainWindow.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<Grid.RowDefinitions>
112112
<RowDefinition Height="Auto" />
113113
<RowDefinition Height="Auto" />
114+
<RowDefinition />
114115
</Grid.RowDefinitions>
115116
<Grid.ColumnDefinitions>
116117
<ColumnDefinition Width="Auto" />
@@ -134,6 +135,17 @@
134135
Maximum="1"
135136
TickFrequency="0.01"
136137
Value="0.85" />
138+
<Label Grid.Row="2"
139+
Grid.Column="0"
140+
Content="Zoom level:" />
141+
<Slider Grid.Row="2"
142+
Grid.Column="1"
143+
Name="zoomSlider"
144+
Minimum="0"
145+
Maximum="1"
146+
TickFrequency="0.1"
147+
Value="0.0"
148+
ValueChanged="SetZoomLevel"/>
137149
</Grid>
138150
</GroupBox>
139151
<Label Name="outputLabel"

CefSharp.Wpf.Example/MainWindow.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public void DisplayOutput(string output)
122122
outputLabel.Content = output;
123123
}
124124

125+
public void SetZoomLevel(object sender, RoutedPropertyChangedEventArgs<double> zoomLevelArgs)
126+
{
127+
web_view.ZoomLevel = zoomLevelArgs.NewValue;
128+
}
129+
125130
private void control_Activated(object sender, RoutedEventArgs e)
126131
{
127132
EventHandler handler;

CefSharp.Wpf/WebView.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ namespace CefSharp
235235
void set(IJsDialogHandler^ handler) { _browserCore->JsDialogHandler = handler; }
236236
}
237237

238+
virtual property double ZoomLevel
239+
{
240+
double get() {
241+
CefRefPtr<CefBrowser> browser;
242+
if(!TryGetCefBrowser(browser)) {
243+
return 0;
244+
}
245+
return browser->GetZoomLevel();
246+
}
247+
void set(double zoomLevel)
248+
{
249+
CefRefPtr<CefBrowser> browser;
250+
if(!TryGetCefBrowser(browser)) {
251+
return;
252+
}
253+
browser->SetZoomLevel(zoomLevel);
254+
}
255+
}
256+
238257
virtual void OnInitialized();
239258

240259
virtual void Load(String^ url);

0 commit comments

Comments
 (0)