Skip to content

Commit cedbbc4

Browse files
committed
#209. Fixed the JS execution UI to be a bit more reasonable, at least.
1 parent 4df9ef3 commit cedbbc4

File tree

2 files changed

+103
-97
lines changed

2 files changed

+103
-97
lines changed

CefSharp.Wpf.Example/Views/Main/MainView.xaml

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -40,107 +40,107 @@
4040
</TextBox.InputBindings>
4141
</TextBox>
4242
</DockPanel>
43-
<Expander VerticalAlignment="Top"
44-
DockPanel.Dock="Top"
45-
Header="Miscellaneous">
46-
<StackPanel>
47-
<GroupBox Header="Tweak WPF Rendering">
48-
<Grid>
49-
<Grid.RowDefinitions>
50-
<RowDefinition Height="Auto" />
51-
<RowDefinition Height="Auto" />
52-
</Grid.RowDefinitions>
53-
<Grid.ColumnDefinitions>
54-
<ColumnDefinition Width="Auto" />
55-
<ColumnDefinition Width="*" />
56-
</Grid.ColumnDefinitions>
57-
<Label Grid.Row="0"
58-
Grid.Column="0"
59-
Content="Angle:" />
60-
<Slider Grid.Row="0"
61-
Grid.Column="1"
62-
Name="angleSlider"
63-
Minimum="-180"
64-
Maximum="180" />
65-
<Label Grid.Row="1"
66-
Grid.Column="0"
67-
Content="Watermark Opacity:" />
68-
<Slider Grid.Row="1"
69-
Grid.Column="1"
70-
Name="opacitySlider"
71-
Minimum="0"
72-
Maximum="1"
73-
TickFrequency="0.01"
74-
Value="0.95" />
75-
</Grid>
76-
</GroupBox>
77-
<GroupBox Header="Javascript Integration"
78-
Margin="0,10,0,0">
79-
<Grid Width="700">
80-
<Grid.RowDefinitions>
81-
<RowDefinition />
82-
<RowDefinition />
83-
<RowDefinition />
84-
<RowDefinition />
85-
</Grid.RowDefinitions>
86-
<Grid.ColumnDefinitions>
87-
<ColumnDefinition Width="Auto" />
88-
<ColumnDefinition />
89-
<ColumnDefinition Width="Auto" />
90-
</Grid.ColumnDefinitions>
91-
<Label Grid.Row="0"
92-
Grid.Column="0">Execute Javascript (asynchronously):</Label>
93-
<TextBox x:Name="ExecuteJavascriptTextBox"
94-
Grid.Row="0"
95-
Grid.Column="1"
96-
Margin="0,0,0,5">
97-
<TextBox.InputBindings>
98-
<KeyBinding Key="Enter"
99-
Command="{Binding ExecuteJavaScriptCommand}"
100-
CommandParameter="{Binding Text, RelativeSource={RelativeSource AncestorType=TextBox}}" />
101-
</TextBox.InputBindings>
102-
103-
alert('Hello World, do you copy?')
104-
</TextBox>
105-
<Button Grid.Row="0"
106-
Grid.Column="2"
107-
Content="Run"
108-
Margin="10,0,0,3"
109-
Padding="5,2"
110-
Command="{Binding ExecuteJavaScriptCommand}"
111-
CommandParameter="{Binding Text, ElementName=ExecuteJavascriptTextBox}" />
112-
113-
<Label Grid.Row="2"
114-
Grid.Column="0">Evaluate Javascript (and display result):</Label>
115-
<TextBox x:Name="EvaluateJavascriptTextBox"
116-
Grid.Row="2"
117-
Grid.Column="1"
118-
Margin="0,5,0,0">
119-
<TextBox.InputBindings>
120-
<KeyBinding Key="Enter"
121-
Command="{Binding EvaluateJavaScriptCommand}"
122-
CommandParameter="{Binding Text, RelativeSource={RelativeSource AncestorType=TextBox}}" />
123-
</TextBox.InputBindings>
124-
125-
$.get('body').length
126-
</TextBox>
127-
<Button Grid.Row="2"
128-
Grid.Column="2"
129-
Content="Run"
130-
Margin="10,3,0,0"
131-
Padding="5,2"
132-
Command="{Binding EvaluateJavaScriptCommand}"
133-
CommandParameter="{Binding Text, ElementName=EvaluateJavascriptTextBox}" />
134-
</Grid>
135-
</GroupBox>
136-
</StackPanel>
137-
</Expander>
43+
<StackPanel DockPanel.Dock="Right">
44+
<GroupBox Header="Tweak WPF Rendering">
45+
<Grid>
46+
<Grid.RowDefinitions>
47+
<RowDefinition Height="Auto" />
48+
<RowDefinition Height="Auto" />
49+
</Grid.RowDefinitions>
50+
<Grid.ColumnDefinitions>
51+
<ColumnDefinition Width="Auto" />
52+
<ColumnDefinition Width="*" />
53+
</Grid.ColumnDefinitions>
54+
<Label Grid.Row="0"
55+
Grid.Column="0"
56+
Content="Angle:" />
57+
<Slider Grid.Row="0"
58+
Grid.Column="1"
59+
Name="angleSlider"
60+
Minimum="-180"
61+
Maximum="180" />
62+
<Label Grid.Row="1"
63+
Grid.Column="0"
64+
Content="Watermark Opacity:" />
65+
<Slider Grid.Row="1"
66+
Grid.Column="1"
67+
Name="opacitySlider"
68+
Minimum="0"
69+
Maximum="1"
70+
TickFrequency="0.01"
71+
Value="0.95" />
72+
</Grid>
73+
</GroupBox>
74+
<GroupBox Header="Execute Javascript (asynchronously)">
75+
<Grid Width="300">
76+
<Grid.RowDefinitions>
77+
<RowDefinition Height="75" />
78+
<RowDefinition Height="Auto" />
79+
</Grid.RowDefinitions>
80+
<TextBox x:Name="ExecuteJavascriptTextBox"
81+
Grid.Row="0"
82+
AcceptsReturn="True"
83+
Margin="6"
84+
Text="alert('Hello World, do you copy?')">
85+
<TextBox.InputBindings>
86+
<KeyBinding Key="Enter"
87+
Modifiers="Control"
88+
Command="{Binding ExecuteJavaScriptCommand}"
89+
CommandParameter="{Binding Text, RelativeSource={RelativeSource AncestorType=TextBox}}" />
90+
</TextBox.InputBindings>
91+
</TextBox>
92+
<Button Grid.Row="1"
93+
HorizontalAlignment="Left"
94+
Margin="6,0,6,6"
95+
Padding="5,2"
96+
Content="Run"
97+
Command="{Binding ExecuteJavaScriptCommand}"
98+
CommandParameter="{Binding Text, ElementName=ExecuteJavascriptTextBox}" />
99+
</Grid>
100+
</GroupBox>
101+
<GroupBox Header="Execute Javascript (synchronously)">
102+
<Grid Width="300">
103+
<Grid.RowDefinitions>
104+
<RowDefinition Height="75" />
105+
<RowDefinition Height="Auto" />
106+
<RowDefinition Height="Auto" />
107+
<RowDefinition Height="Auto" />
108+
</Grid.RowDefinitions>
109+
<TextBox x:Name="EvaluateJavascriptTextBox"
110+
Grid.Row="0"
111+
Margin="6"
112+
AcceptsReturn="True"
113+
Text="$('body').children().length">
114+
<TextBox.InputBindings>
115+
<KeyBinding Key="Enter"
116+
Modifiers="Control"
117+
Command="{Binding EvaluateJavaScriptCommand}"
118+
CommandParameter="{Binding Text, RelativeSource={RelativeSource AncestorType=TextBox}}" />
119+
</TextBox.InputBindings>
120+
</TextBox>
121+
<Button Grid.Row="1"
122+
HorizontalAlignment="Left"
123+
Margin="6,0"
124+
Padding="5,2"
125+
Content="Run"
126+
Command="{Binding EvaluateJavaScriptCommand}"
127+
CommandParameter="{Binding Text, ElementName=EvaluateJavascriptTextBox}" />
128+
<TextBlock Grid.Row="2"
129+
Margin="6">Result:</TextBlock>
130+
<TextBox Grid.Row="3"
131+
IsReadOnly="True"
132+
Margin="6,0,6,6"
133+
Text="{Binding EvaluateJavaScriptResult}" />
134+
</Grid>
135+
</GroupBox>
136+
</StackPanel>
138137
<StatusBar DockPanel.Dock="Bottom">
139138
<ProgressBar HorizontalAlignment="Right"
140139
IsIndeterminate="{Binding WebBrowser.IsLoading}"
141140
Width="100"
142141
Height="16"
143142
Margin="3" />
143+
<!-- TODO: Show hover link URL here -->
144144
<Separator />
145145
<TextBlock Text="{Binding OutputMessage}" />
146146
</StatusBar>

CefSharp.Wpf.Example/Views/Main/MainViewModel.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public IWpfWebBrowser WebBrowser
4444
set { PropertyChanged.ChangeAndNotify(ref webBrowser, value, () => WebBrowser); }
4545
}
4646

47+
private object evaluateJavaScriptResult;
48+
public object EvaluateJavaScriptResult
49+
{
50+
get { return evaluateJavaScriptResult; }
51+
set { PropertyChanged.ChangeAndNotify(ref evaluateJavaScriptResult, value, () => EvaluateJavaScriptResult); }
52+
}
53+
4754
public DelegateCommand GoCommand { get; set; }
4855
public DelegateCommand ViewSourceCommand { get; set; }
4956
public DelegateCommand HomeCommand { get; set; }
@@ -73,8 +80,7 @@ private void EvaluateJavaScript(string s)
7380
{
7481
try
7582
{
76-
var result = webBrowser.EvaluateScript(s) ?? "null";
77-
MessageBox.Show("Result: " + result);
83+
EvaluateJavaScriptResult = webBrowser.EvaluateScript(s) ?? "null";
7884
}
7985
catch (Exception e)
8086
{

0 commit comments

Comments
 (0)