How do I link a WPF app to a Telerik Report? - wpf

I created a Report Library with a report.
I created a WPF App.
I added a Report Viewer to the WPF App & pointed it to the report.
How do I link everything together?
The data within the WPF App needs to be in the report.
My Solution:
I added a “data” DLL and dded a reference to the data DLL to both the report & the WPF App.
When I run the program:
instance not found
OK, that makes sense since there’s no link.
After the WPF App instantiates the data, how is this instance linked to the report?

Key idea:
Within the Report's code behind,
protected override void OnNeedDataSource(object sender, System.EventArgs e)
In the constructor
Report.DataSource = null;
// "At runtime Report.NeedDataSource event is raised only when the report has no data source set"
Pass the data from the App to the Report as a parameter.
// This is a work in progress...

Related

Calling commands across the app domain boundary WPF

I'm working on an MVVM and AddIns-based application. I want to build the menu (ribbon control) dynamically through the AddIn module which will contain MVVM based assembly. On the host side, I'm unable to fire the command which is bound through ViewModel, which is hosted in separate appdomain from host application. How should I approach this issue of dynamic ribbon tabs generation with all bindings to commands/icons from the respective AddIn module.
Edit:
I've developed an MVVM-based application. All application state and commands are in ViewModel and that is bound to the View, which works as expected.
Afterwards, we write code using Managed Addin Framework (MAF) for .net and incorporated that application through it. The issue is coming that we are unable to generate a menu based on the commands in the Addin at the host side. I wrote a property to return menus from the ViewModel Addin to the host, but it just returns the plain objects and commands do not get propagated through AddIn Framework. Here is a code sample:
public IEnumerable<TabViewModel> MenuTabs
{
get
{
var tab = new TabViewModel{ Header = "Tab 1"};
var group = new GroupViewModel {Header = "Group 1"};
var button = new ButtonViewModel{Content = "Say Hello", Command = HelloCommand};
group.Buttons.Add(button);
tab.Groups.Add(group);
return new[] {tab};
}
}
This code is written in say TestViewModel, and HelloCommand is an implementation of ICommand interface from WPF input library. The HelloCommand does not reach at the host side everything else is available and I'm getting Ribbon control's tabs and groups properly, but the commands are not being transmitted to the Addin Host.
Edit2
The issue is that, we want to show the Ribbon in the AddIn-Host window those buttons refer to the commands in AddIn's ViewModel, the final thing (i can) is to move the menu control to the AddIn too. Has someone encountered same problem and want to share the experience?

Silverlight 4: Fields disapear in data grid after saving en

When saving a new entity something strange happens...
I have a data grid with a list of 'Depots' populated using a domain data source.
When the user wants to add a new 'Depot' this is what happens:
Depot newDepot = new Depot();
newDepot.Name = "My New Depot";
EditDepot popup = new EditDepot(newDepot); // create the popup and pass the newly created Depot
domainDataSource.DataView.Add(newDepot); // add a new Depot to the datagrid
// handle the popup events
popup.CancelClick += (cancelSender, cancelArgs) =>
{
if (GridDataSource.DataView.Contains(newDepot))
domainDataSource.DataView.Remove(newDepot);
domainDataSource.DomainContext.RejectChanges();
};
popup.Show();
The popup constructor then passes the entity to a viewmodel. The viewmodel constructor then creates a new instance of 'ContactInfo', another entity which is linked to 'Depot' (Depot.ContactInfo). After filling in a few properties, the 'Depot' is assigned to a property in the viewmodel and a dataform is used to edit the data. Once the user is happy with the content they will press save. The Depot is added to the context (Context.Depots.Add....) and then the changes are submitted. (It's also worth noting I have tried added the ContactInfo item to the context too, with no joy). The data is saved to the database (via WCF) and everything appears to have worked correctly. The proplem is the datagrid is not displaying the ContactInfo fields, where as it did before the save. As the user edits the data, you can see the datagrid populated behind the popup. If the user refreshes, the data returns. This problem does not happen when the entity is editied.
Now, to throw another spanner in the works... This doesn't happen on all our machines...
We have a build machine and the output does have this problem, however one machine in the building builds a version which does not have this problem! After some investigation, we have found that it appears to be the version of WCF RIA Services. On my machine, I had V1.0 SP1. I Tried V1.0 SP2 and still had the same problem. Now on the machine that works, WCF RIA Services SP1 Beta was installed. After he unistalled this, and installed SP2, the problem occured on his machine.
So, we are relutant to use a beta version in our final release, but unless we can fix this issue we wont have a choice. Does anyone have any ideas? Has anyone seen this issue before?
I have also tried different version of the WCF toolkit with no joy
EDIT: I've created a simple project to show you whats happening
The project retrieves a load of entities and tries to add one. You'll notice the the 'InnerThing' properties dissapear.
Link to project
the issue was that the key property was being set in the insert method in the service.
it looks like this change was not reflected in the client. Changing other properties in the service after submit other than the key did work however.

Web Browser Control in WPF App with no airspace issue?

I am working on a WPF app which has Web Browser in one of its views. When I run the Application, It works fine but the Web Browser Control sits on top of my wpf region. I know this is something to do with the AirSpace issue. Is there any possible way to get over it? Any help will be appreciated.
Thanks
The issue was not solved in WPF 4.5.
There were some information in net such the below mentioned properties would be available with the 4.5 version of web browser control, however the plan has been dropped. So you need to handle the airspace issue by yourself.
WebBrowser.CompositionMode = System.Windows.Interop.CompositionMode.Full;
WebBrowser.IsRedirected = true;
The workaround that you could do is by making the height of the web browser control to zero, when some other control comes in front of Web browser control.
Find sample code below,
Assume, you have a web browser control in Mainwindow. When you perform some action,, eg: click a button you have another user control which comes above MainWindow. However, because of Airspace issue the web browser doesn't sit in its parent control and comes on top of your control.
FIX:
The standard fix is you can set the height of web browser to zero when you trigger some other control over it depends upon your scenario. Below, there is a sample implementation.
In MainWindow.Xaml include the events.
Activated="Window_Activated"
Deactivated="Window_Deactivated"
In Xaml.cs handle the scenario by setting the height.
private void Window_Activated(object sender, EventArgs e)
{
wb.Height = double.NaN;
}
private void Window_Deactivated(object sender, EventArgs e)
{
wb.Height = 0;
}
Here is technical information for why this happens.
Some tips and suggestions to get rid of that
This is a known problems, as Neeraj posts. But with WPF 4.5 this seems to be solved, so if you don't mind using the beta version you should download Visual Studio 11.
Try Chris84898's AirspaceFixer project.
https://github.com/chris84948/AirspaceFixer
You just host the problematic control inside a panel, and it does the heavy lifting for you.
XAML:
<asf:AirspacePanel x:Name="ap"
FixAirspace="{Binding FixAirspace}"
Grid.Column="0" Grid.Row="1" >
<WebBrowser x:Name="browser" Navigated="Browser_Navigated" />
</asf:AirspacePanel>
To temporarily "FixAirspace" in code (or through dependency property changes):
ap.FixAirspace = true;
// Display a dialog or whatever
ap.FixAirspace = false;
There is a NuGet package for it as well.

When to Call ViewModel.LoadData?

I have a WP7 Silverlight app that displays a bunch of data using Pivot. When first creating the project, the Visual Studio template calls ViewModel.LoadData in Page_Loaded:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
App.ViewModel.LoadData();
}
However on MSDN it says you should use OnNavigatedTo instead of Page_Loaded, because OnNavigatedTo is called only once when a page becomes active, while Page_Loaded is called everytime an item is added to the page's visual tree. The MSDN article is for Silverlight 4 instead of for Silverlight Windows Phone though.
You override the OnNavigatedTo method
to examine the navigation request and
prepare the page for display. For
example, you can load the requested
data and enable or disable visual
elements.
Typically, you use the OnNavigatedTo
method instead of creating an event
handler for the Loaded event. The
OnNavigatedTo method is preferable
because it is only called once for
each time the page becomes active. The
Silverlight framework raises the
Loaded event each time the element is
added to the visual tree, which
potentially can happen more than once
when activating a page. The
OnNavigatedTo method is called for
each request, even when the page is
retrieved from the cache. You should
include in this method code that must
be executed for each request rather
than placing that code in the Page
constructor.
Is there any reason why the Visual Studio Pivot template calls ViewModel.LoadData in Page_Loaded?
I think you're confusing LayoutUpdated and Loaded.
Loaded should only get called once each time the page is displayed.
Loading data specific to a page after that page has been constructed is a simple way of working with data tied to a specific page. My guess is that the default templates use this as it's simple to understand and learn from.
Update
The article in MSDN that you refer to is for Page.Loaded. WP7 does not use Page instead it uses PhoneApplicationpage.
Having worked with WP7 for over a year and created dozens of apps, I've never seen the Loaded event called multiple times in a WP7 app.

How can I get a Silverlight application to check for an update and ask user to upgrade?

I have made an out-of-browser silverlight application which I want to automatically update every time there is a new .xap file uploaded to the server.
When the user right-clicks the application and clicks on Updates, the default is set to "Check for updates, but let me choose whether to download and install them":
(source: deviantsart.com)
This leads me to believe that it is possible to make my Silverlight application automatically detect if there is a new .xap file present on the server, and if there is, the Silverlight client will automatically ask the user if he would like to install it.
This however is not the case. I upload a new .xap file and the Silverlight application does nothing.
Even if I add this to my App.xaml.cs:
--
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new BaseApp();
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateAsync();
}
}
and update the .xap file, the Silverlight application does nothing.
This information enabled me to check if there is an update and if so, tell the user to restart the application, but when he restarts the application, nothing happens:
--
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new BaseApp();
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateAsync();
Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
}
}
void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.UpdateAvailable)
{
MessageBox.Show("An application update has been downloaded. " +
"Restart the application to run the new version.");
}
else if (e.Error != null &&
e.Error is PlatformNotSupportedException)
{
MessageBox.Show("An application update is available, " +
"but it requires a new version of Silverlight. " +
"Visit the application home page to upgrade.");
}
else
{
//no new version available
}
}
How do I make my Silverlight application check, each time it starts, if there is a new .xap file, and if there is, pass control to the Silverlight client to ask the user if he wants to download it, as the above dialogue implies is possible?
The first dialog is about how updates to Silverlight itself are installed and has nothing to do with your application.
Using the CheckAndDownloadUpdateAsync the new XAP should be downloaded automatically. Acording to the doc there is no way to prevent the new version from being installed one you call CheckAndDownloadUpdateAsync.
The screen you are refering to the is not specific to any silverlight application. Its refering to the silverlight plugin itself.
The CheckAndDownloadUpdateAsync method should have downloaded the newer version but the user will need to restart the application in order to start using the new application. You use the UpdateAvailable property of the event args in the completed event to determine whether to ask the user to restart.
You might get what you're wanting by incorporating an external version control check. have it look to see if the version that's installed and the version on the server is different.
If it's different ask the user if they want to update. If they choose yes, then invoke CheckAndDownloadUpdateAsync();
otherwise skip it if they choose no or if the version is the same.
there are many ways to do your own versioning checks. Including static readonly properties that are populated # build time and have some kind of similar result on an http request.
You could use the webclient to grab a response from the server and compare that with the currently loaded version of the application.
You can incorporate a method on the callback to go to show a message that tells the user to restart the app.

Resources