Binding silverlight combox in entity framework c# - silverlight-4.0

I am new in silverlight and i want to
bind data from Entity Data source in combox
like WindosForm
for exmple
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DisplayMember = "CategoryName";
comboBox1.ValueMember = "CategoryID";
comboBox1.DataSource = NorthwindEntities.Categories;
}
Thank you all.

Here you go
comboBox1.ItemSource= NorthwindEntities.Categories;
and you need to post XAML for more help.

Related

Registering RoutedEventHandler in UWP template control

I'm having difficulty finding how to register a RoutedEventHandler in UWP. I'm attempting to code a template control that has event properties similar to ContentDialog's:
PrimaryButtonClick="ClickEvent"
Where ClickEvent is defined in the cs file. I'm only just getting the hang of templates, but I believe I want to do something that looks like this:
<Button Content="{TemplateBinding PrimaryButtonText}" Click="{TemplateBinding PrimaryButtonClick}"/>
Currently, all I can find is references to WPF versions of this type of code:
public static readonly RoutedEvent ValueChangedEvent =
EventManager.RegisterRoutedEvent("ValueChanged",
RoutingStrategy.Direct, typeof(RoutedPropertyChangedEventHandler<double>),
typeof(NumericBox));
public event RoutedPropertyChangedEventHandler<double> ValueChanged
{
add { AddHandler(ValueChangedEvent, value); }
remove { RemoveHandler(ValueChangedEvent, value); }
}
private void OnValueChanged(double oldValue, double newValue)
{
RoutedPropertyChangedEventArgs<double> args =
new RoutedPropertyChangedEventArgs<double>(oldValue, newValue);
args.RoutedEvent = NumericBox.ValueChangedEvent;
RaiseEvent(args);
}
But of course the types have changed. Can someone point me in the right direction?
Unfortunately, the concept of RoutedEvent (bubbling, tunneling) is not available in UWP currently. You can just create a classic event however instead:
public event EventHandler PrimaryButtonClick;
protected void InnerButton_Click(object sender, EventArgs e)
{
PrimaryButtonClick?.Invoke( sender, e );
}
Bubbling of events is possible for some predefined events, but it is not yet possible to allow bubbling for custom events in current version of UWP.

XAML navigation in Windows Store Grid App

I trying to navigate between XAML pages in grid app. for this i have added a added a new XAML and a button in XAML and cs code for button event is
private void OnClick(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof (GroupedItemsPage));
}
on clicking this button my app should navigate to GroupedItemsPage, but instead it raises an null exception
try this :
private void OnClick(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof (GroupedItemsPage));
}
Please have a look there, too.

Work with WCF methods Async Call Result

I am using Silverlight 4 with WCF Services for my database interaction . I am facing one problem.
Function all in silverlight application.
ServiceReference1.WCFSLServicesClient wc = new ServiceReference1.WCFSLServicesClient();
private void button1_Click(object sender, RoutedEventArgs e)
{
_wait = new ManualResetEvent(false);
wc.SayHelloCompleted += new EventHandler<ServiceReference1.SayHelloCompletedEventArgs>(wc_SayHelloCompleted);
wc.SayHelloAsync("Mr. X");
//wait untill the call finish and then move next like
//Here I want to do some thing with result of above call. And then proceed to next task .
}
String Name = String.Empty;
void wc_SayHelloCompleted(object sender, ServiceReference1.SayHelloCompletedEventArgs e)
{
Name =e.Result;
}
But all methods calls in Silver light are Async so I am not able to Get this out.
Put whatever it is you want to do into another method and call that method from your Completed Handler.
void wc_SayHelloCompleted(object sender, ServiceReference1.SayHelloCompletedEventArgs e)
{
Name =e.Result;
MyNewMethod(Name);
}

Configuration which one should I be using? From fluent tutorial or from cookbook 3.0?

I am reading nhibernate cookbook 3.0 and the fluent tutorial and I am kinda confused which one I should be using(cookbook by itself has many different ways)
Fluent Nhibernate tutorial
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(
SQLiteConfiguration.Standard
.UsingFile("firstProject.db")
)
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<Program>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
private static void BuildSchema(Configuration config)
{
// delete the existing db on each run
if (File.Exists(DbFile))
File.Delete(DbFile);
// this NHibernate tool takes a configuration (with mapping info in)
// and exports a database schema from it
new SchemaExport(config)
.Create(false, true);
}
cookbook 3.0 pg(76) web request
1. In the hibernate-configuration section of web.config, add the current_
session_context_class property with a value of web.
2. If it doesn't exist already, add a new Global application class (Global.asax).
3. In Global.asax, add these using statements.
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
4. Create a static property named SessionFactory.
public static ISessionFactory SessionFactory { get;
private set; }
5. In the Application_Start method, add the following code.
protected void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
var nhConfig = new Configuration().Configure();
SessionFactory = nhConfig.BuildSessionFactory();
}
6. In the Application_BeginRequest method, add the following code.
protected void Application_BeginRequest(object sender, EventArgs e)
{
var session = SessionFactory.OpenSession();
CurrentSessionContext.Bind(session);
}
7. In the Application_EndRequest method, add the following code:
protected void Application_EndRequest(object sender, EventArgs e)
{
var session = CurrentSessionContext.Unbind(SessionFactory);
session.Dispose();
}
Then they just use this to run it.
Guid productId = new Guid(Request["id"]);
Eg.Core.Product product;
var session = Global.SessionFactory.GetCurrentSession();
using (var tran = session.BeginTransaction())
{
product = session.Get<Eg.Core.Product>(productId);
tran.Commit();
}
Page.Title = product.Name;
Label1.Text = product.Name;
Label2.Text = product.Description;
With the fluent tutorial I am also kinda confused where I would typically put that code in an asp.net mvc application. I am trying to use the repository pattern with ninject(DI injection).
So with both ways I am not sure how to make it work with ninject and the repository pattern.
Is either way better for the repository pattern and Di?
Did you try to download the whole solution to run the project? These are just samples of code and you need the whole setup: VS project with Entity classes, mappings, repositories etc.
I would go to http://www.sharparchitecture.net/ and https://github.com/sharparchitecture download their Northwind sample project that has the exact setup that you need. You will have to find the Northwind database and install it on you local machine then modify the NHibernate.config to point to your database.

Editing Data in Child Window with RIA Services and Silverlight 4

Is it possible to edit data in a SilverLight Child window when using RIA Services and Silverlight 4? It sounds like a simple enough question, but I have not been able to get any combination of scenarios to work.
Simply put, I am viewing data in a grid that was populated through a DomainDataSource. Instead of editing the data on the same screen (this is the pattern that ALL of the Microsoft samples seem to use), I want to open a child window, edit the data and return. Surely this is a common design pattern.
If anyone knows of a sample out there that uses this pattern, a link would be much appreciated.
Thanks,
Rick Arthur
This is a Microsoft sample that uses a ChildWindow. It uses RIA services, but not MVVM.
It doesn't fix a problem I'm having where entities get attached to my context before I want them to be, but does what you're looking for other than that.
Here's the relevant code to save you downloading the zip:
private void addNewEmployee_Click(object sender, RoutedEventArgs e)
{
EmployeeRegistrationWindow addEmp = new EmployeeRegistrationWindow();
addEmp.Closed += new EventHandler(addEmp_Closed);
addEmp.Show();
}
public partial class EmployeeRegistrationWindow : ChildWindow
{
public EmployeeRegistrationWindow()
{
InitializeComponent();
NewEmployee = new Employee();
addEmployeeDataForm.CurrentItem = NewEmployee;
addEmployeeDataForm.BeginEdit();
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
addEmployeeDataForm.CommitEdit();
this.DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
NewEmployee = null;
addEmployeeDataForm.CancelEdit();
this.DialogResult = false;
}
public Employee NewEmployee { get; set; }
}
The MVVM light Toolkit found here has messeging between viewmodels for more information check above site. Please write if u need an example.