webbrowser control LoadCompleted Event Not Firing when Using NavigateToString Silverlight 5 - silverlight

I am working in Silverlight 5 webbrowser control to show the Contents. I have Used this Code Which Worked Fine For me.
Xaml:
<TextBox x:Name="txtUri" Margin="5" HorizontalAlignment="Stretch" />
<Button x:Name="btnGo" Grid.Column="1" Content="Go" Click="OnGo" Margin="5" />
<WebBrowser LoadCompleted="browserControl_LoadCompleted" ScriptNotify="browserControl_ScriptNotify" Grid.Row="1" Margin="5" x:Name="browserControl" />
.CS
private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show("called");
}
private void browserControl_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show("called");
btnGo.IsEnabled = true;
}
private void OnGo(object sender, RoutedEventArgs e)
{
btnGo.IsEnabled = false;
browserControl.Navigate(new Uri(txtUri.Text, UriKind.RelativeOrAbsolute));
}
private void browserControl_ScriptNotify(object sender, NotifyEventArgs e)
{
if (!string.IsNullOrEmpty(e.Value))
{
MessageBox.Show(e.Value);
}
}
It Disable the Button And Search For TextBox entered URI but When i change the OnGo Method
private void OnGo(object sender, RoutedEventArgs e)
{
btnGo.IsEnabled = false;
browserControl.NavigateToString("<html> <head><title>Sample Readme File</title><script type='text/javascript' language='javascript'> function GetSelectedText() {window.external.notify('Text to show in Message box');}</script></head> <body> <a onclick='GetSelectedText()'>Click Me</a> <p>Sample Readme Content</p> </body></html>");
}
And Add the ScriptNotify Event Handler
void webBrowser_ScriptNotify(object sender, NotifyEventArgs e)
{
if (!string.IsNullOrEmpty(e.Value))
{
MessageBox.Show(e.Value);
}
}
Then webBrowser_LoadCompleted event does not Triggered.
What is the difference behind these two.
Please Help!

Related

WPF Scatterview items - how to clear all the items by clicking a button?

I created a button and wrote its behaviour to clear the scatter view, but it didnt work:
private void Button1_Click(object sender, RoutedEventArgs e)
{
DependencyObject parent = VisualTreeHelper.GetParent(this);
ScatterViewItem svi = null;
while (parent as ScatterView == null)
{
if (parent is ScatterViewItem)
svi = parent as ScatterViewItem;
parent = VisualTreeHelper.GetParent(parent);
}
((ScatterView)parent).Items.Remove(svi);
}
Before this, I thought to reset the application by this code which didnt work either: (I added using System.Diagnostics; )
private void Button1_Click(object sender, RoutedEventArgs e)
{
Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
}
the xaml:
<s:SurfaceButton Content="Clear" Name="Button1" Click="Button1_Click" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
can you tell me what i miss,
thanks
You can simply give the ScatterView a name
<s:ScatterView x:Name="scatterView" ... />
and then access it from code behind:
private void Button1_Click(object sender, RoutedEventArgs e)
{
scatterView.Items.Clear();
}

What is the equivalent of a Button Click in DevExpress?

In WPF, a button and a click event is:
<Button Click="Btn_Click" />
private void Btn_Click(object sender, RoutedEventArgs e)
{
....
}
In DevExpress, according to the documentation, I would guess the equivalent would be:
<dxb:BarButtonItem ItemClick="Btn_Click" />
private event ItemClickEventHandler Btn_Click(Item sender, RoutedEvent e)
{
....
}
But it is not compiling. I would guess it is very easy but I cannot find any example in the documentation.
The second parameter of the handler should be a ItemClickEventArgs:
private void Btn_Click(object sender, ItemClickEventArgs e)
{
....
}

Can't get simple WPF drag and drop to work

For a simple test I want to drag a Button to a TextBox. I can start dragging the Button, but the Drop event is not raised. What am I missing?
Xaml:
<Window x:Class="DayPlanner.View.DnDTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DnDTest" Height="200" Width="200">
<StackPanel>
<Button Name="button"
Content="OK"
PreviewMouseLeftButtonDown="button_PreviewMouseLeftButtonDown"
PreviewMouseMove="button_PreviewMouseMove"/>
<TextBox Name="textBox"
AllowDrop="True"
DragEnter="textBox_DragEnter"
Drop="textBox_Drop"/>
</StackPanel>
</Window>
Code:
public partial class DnDTest : Window
{
public DnDTest()
{
InitializeComponent();
}
private Point dragStartPoint;
private void button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dragStartPoint = e.GetPosition(null);
}
private static bool IsDragging(Point dragStartPoint, MouseEventArgs e)
{
var diff = e.GetPosition(null) - dragStartPoint;
return
e.LeftButton == MouseButtonState.Pressed &&
(Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance);
}
private void button_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (IsDragging(dragStartPoint, e))
{
DragDrop.DoDragDrop(button, new DataObject("Button", button), DragDropEffects.Move);
e.Handled = true;
}
}
private void textBox_DragEnter(object sender, DragEventArgs e)
{
e.Handled = true;
}
private void textBox_Drop(object sender, DragEventArgs e)
{
var button = (Button)e.Data.GetData("Button");
textBox.Text = string.Format("[0]", button.Content.ToString());
e.Handled = true;
}
}
This might be some strange case, but to fix it, I needed to handle or dragging events, including the Preview versions.
Here's how to make it work.
Xaml:
<Window x:Class="DayPlanner.View.DnDTestBasic"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DnDTestBasic" Height="200" Width="200">
<StackPanel>
<Button Name="button"
Content="OK"
PreviewMouseLeftButtonDown="button_PreviewMouseLeftButtonDown"
PreviewMouseMove="button_PreviewMouseMove"/>
<TextBox Name="textBox"
AllowDrop="True"
PreviewDragEnter="textBox_Dragging"
DragEnter="textBox_Dragging"
PreviewDragOver="textBox_Dragging"
DragOver="textBox_Dragging"
Drop="textBox_Drop"/>
<TextBlock Name="status"
Text="No dragging"/>
</StackPanel>
</Window>
Code:
public partial class DnDTestBasic : Window
{
public DnDTestBasic()
{
InitializeComponent();
}
private Point dragStartPoint;
private void button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dragStartPoint = e.GetPosition(null);
status.Text = "New drag start position";
}
private static bool IsDragging(Point dragStartPoint, MouseEventArgs e)
{
var diff = e.GetPosition(null) - dragStartPoint;
return
e.LeftButton == MouseButtonState.Pressed &&
(Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance);
}
private void button_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (IsDragging(dragStartPoint, e))
{
status.Text = "Starting drag...";
DragDrop.DoDragDrop(button, new DataObject("Button", button), DragDropEffects.Copy);
status.Text = "Dragging done.";
e.Handled = true;
}
}
private void textBox_Dragging(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("Button"))
e.Effects = DragDropEffects.Copy;
else
e.Effects = DragDropEffects.None;
e.Handled = true;
}
private void textBox_Drop(object sender, DragEventArgs e)
{
var button = (Button)e.Data.GetData("Button");
textBox.Text = string.Format("[{0}]", button.Content.ToString());
e.Handled = true;
}
}
I believe it has to do with the fact that when you start the drag event, the button control is capturing mouse input. Any mouse movements you do after that are registered to the button instead of to the application
I actually had a similar problem and ended up using MouseEnter/Leave events instead of the built in WPF drag/drop framework.

Slider control in silverlight

I am using slider control for an audio player in silverlight application. The slider is not moving while audio is playing.
The below one is my XAML code . How to get it?
<Slider x:Name="Slider" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2"
MouseLeftButtonDown="MouseClicked" MouseLeftButtonUp="MouseReleased"
ValueChanged="Slider_ValueChanged" Height="30" Width="484" ></Slider>
Code behind for slider events:
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Audio.Pause();
Audio.Position = TimeSpan.FromSeconds(Slider.Value);
Audio.Play();
}
private void MouseClicked(object sender, MouseButtonEventArgs e)
{
Audio.Pause();
Audio.Position = TimeSpan.FromSeconds(Slider.Value);
}
private void MouseReleased(object sender, MouseButtonEventArgs e)
{
Audio.Play();
}
In Silverlight 3(as i know) MouseLeftButtonDown not working. You need to create own Handler in code. For example :
progress_bar.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(progress_bar_MouseLeftButtonDown), true);

How to do silverlight 3 blur effect in code behind?

The blur effect in silverlight 3 is nice:
<StackPanel HorizontalAlignment="Left">
<Button x:Name="Button1"
Content="Click This"
Click="Button1_Click">
<Button.Effect>
<BlurEffect Radius="2"/>
</Button.Effect>
</Button>
</StackPanel>
But how would I do it in code behind:
private void Button1_Click(object sender, RoutedEventArgs e)
{
Button1.Content = "was clicked";
//Button1.Effect.bl...
}
Silverlight 3 only
private void Button1_Click(object sender, RoutedEventArgs e)
{
((Button)sender).Content = "was clicked";
((Button)sender).Effect = new BlurEffect { Radius = 8 };
}

Resources