XamlParseException converting string to routed event handler - wpf

I keep getting the error:
ArgumentException: Object of type 'System.String' cannot be converted to type 'System.Windows.RoutedEventHandler'.
When I try to run an app. The component causing the error is the filter control component I downloaded here. I have successfully used this component for the same type of application before so I don't think it is the component code.
The only difference between the 2 apps I can tell is the wpf page that loads the component sits in a different assembly than the wpf window that loads the page.
Any ideas why this would be happening?
Here's the XAML:
<FCC:FilterControl x:Name="EquipNumFilterBox" Height="25" Header="Filter..." Margin="10,2,0,0" Filter="FilterBox_Filter" ClearFilter="FilterBox_ClearFilter"/>
Here's the code behind:
private void FilterBox_Filter(object sender, FilterControlComponent.FilterEventArgs e)
{
e.IsFilterApplied = true;
((CollectionViewSource)this.Resources["theDataView"]).View.Refresh();
}
private void FilterBox_ClearFilter(object sender, RoutedEventArgs e)
{
((CollectionViewSource)this.Resources["theDataView"]).View.Refresh();
}

Managed to get around this by assigning the event in the code behind.

Related

javascript bounded cant change form object visible false

I changed cefsharp winforms example.
it bound callback.
browser.RegisterJsObject("bound", new BrowserForm());
it bound BrowserForm to can access from java to call AddTab from java
I successfully called c# methods from javascript via bound.
my problem is I cant hide image object when calling from java.
but with button on form we can do.
c# code
public void Load_successfull()
{
MessageBox.Show("working good.");
loading_animation.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
Load_successfull();
}
java code:
bound.load_successfull();
when called from java cant hide loading_animation

Is there any way to get MainWindow in custom control without using Application class?

I have one custom control which is placed inside the WPF Window,is there any possibility to get that WPF Window in Custom control and hook some events on that Window? without using Application class(ex Application.Current.Mainwindow)
Ahh... how about the Window.GetWindow method?:
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Window parentWindow = Window.GetWindow(this);
}
Note that it won't work in the constructor, but if you use the Loaded event, it works just fine.

Navigate back button with ssrs in Silverlight app

I have a Silverlight application which has a RadHtmlPlaceholder which points to ssrs to display reports like so:
<telerik:RadHtmlPlaceholder SourceUrl="http://serverName/ReportServer/Pages/ReportViewer.aspx?/Northwind/Employees&rs:Command=render" />
This works fine but when I have a report that allows you to drill down to display a child report, there is no way of getting back to the parent report without having to load the whole lot again. There doesn't seem to be an option to turn on the navigate back button toolbar option and I've seen other ways of implementing a back button by using javascript to set the window location back one in the history, but obviously this won't work in a Silverlight application. Is there anyway to implement a navigate back button?
Take a look at this thread over in the Telerik forums: http://www.telerik.com/community/forums/silverlight/htmlplaceholder/html-place-holder-back-forward-refresh.aspx
Basically you need to get a handle on the IFrame from the presenter and inject some JavaScript. The history object also has a length property you can use to evaluate if your buttons should be enabled.
public MainPage()
{
InitializeComponent();
// Get the IFrame from the HtmlPresenter
HtmlElement iframe = (HtmlElement)htmlPlaceholder.HtmlPresenter.Children[0];
// Set an ID to the IFrame so that can be used later when calling the javascript
iframe.SetAttribute("id", "myIFrame");
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.location.reload(true);";
HtmlPage.Window.Eval(code);
}
private void Back_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.history.back();";
HtmlPage.Window.Eval(code);
}
private void Forward_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.history.forward();";
HtmlPage.Window.Eval(code);
}
}

Control Initialization Order Fiasco

Consider the following code:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<Slider ValueChanged="slider_ValueChanged/>
<TextBox x:Name="counter"/>
</StackPanel>
</Window>
and
namespace Project1
{
public partial class Window1 : Window
{
public MainWindow() { InitializeComponent(); }
void slider_ValueChanged(object sender,
RoutedPropertyChangedEventArgs<double> e)
{
counter.Text = e.NewValue.ToString();
}
}
}
Slider will raise its ValueChanged event during initialization while counter is still null.
This is an example of a larger problem that I've been running into using WPF, that UI events can fire at any time, and that there is no single place where I can put my initialization code so that it's guaranteed to run after all the pointers owned by the WPF system have been initialized but before any UI events have fired.
What is the most elegant way to deal with this? The fact that this specific example should use data binding is beside the point.
There are many ways to deal with this, depending on your situation
First off, you could simply recognize the fact that the object might not be initialized and check for that before processing. For example,
if (counter.Text != null)
counter.Text = e.NewValue.ToString();
Second, you could attach your events in the Loaded event of the object so they don't fire until after the object has been initialized.
void Counter_Loaded(object sender, EventArgs e)
{
slider.ValueChanged += Slider_ValueChanged;
}
void Counter_Unloaded(object sender, EventArgs e)
{
slider.ValueChanged -= Slider_ValueChanged;
}
And last of all, you can use WPF's Dispatcher to run events on the UI thread at a different DispatcherPriority. The default is Normal, which runs after Loaded, Render, and DataBind operations
Dispatcher.BeginInvoke(DispatcherPriority.DataBind,
new Action(delegate() { counter.Text = e.NewValue.ToString(); }));
The true answer to this question is to use the MVVM pattern where window code behind files contain little to no initialization code.
In this pattern, the UI is connected to the rest of the code with data binding only. You write special view-model classes that implement INotifyPropertyChanged and take your business logic and expose it as a series of properties that UI binds to.
Naturally, you fully control how your view-models initialize.

Storyboard does not start again

I've got a carousel that works fine on a silverlight app, it comes from this website :
Carousel app
Now i want to convert it into a WPF app. This issue is that the storyboard does not start again when the storyboard.begin() is called in StoryBoard.Completed event
private Storyboard timer;
public override void OnApplyTemplate()
{
this.timer.Completed -= new EventHandler(timer_Completed);
this.timer.Completed += new EventHandler(timer_Completed);
this.timer.Begin();
}
void timer_Completed(object sender, EventArgs e)
{
///Code to animate the carousel
this.timer.Begin();
}
The storyboard is initialized in the OnApplyTemplate, retrieving it by is name defined in xaml
Only one Completed event occurs
Thanks for your help
Did you clip some code out of here? I'd guess it isn't actually getting to the Begin() call at the end of timer_Completed, possibly some exception happening before that.

Resources