Baffa

Hi,

I am working with XBAP applications, Visual Studio 2005, and I need bind a list of Users to a listbox. I have developed a C# class with namespace flashOfficerModel, it was compiled OK, the code is below:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Collections.ObjectModel;

namespace flashOfficerModel
{
public class UserList : ObservableCollection<User> {

public UserList() {

fill the user list ...
}
}
}

My XAML page is listed below:

<Page x:Class="flashOfficer.Home"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="flashOfficerModel"

Title="Home"

>

<Page.Resources>

<local:UserList x:Key="UserList" />

<Style TargetType="Hyperlink" x:Key="MainToolbarLink">

<Setter Property="FontSize" Value="12"/>

<Setter Property="FontWeight" Value="Normal"/>

<Setter Property="FontFamily" Value="Tahoma, Trebuchet MS, Arial"/>

<Setter Property="Foreground" Value="#012559"/>

</Style>

<DataTemplate x:Key="UserListTemplate">

<StackPanel Orientation="Horizontal">

<TextBlock Text="{Binding Path=userName}" />

<TextBlock Text=" " />

<TextBlock Text="{Binding Path=userEmail}" />

</StackPanel>

</DataTemplate>

</Page.Resources>

The line marked gives an error:

Warning 1 The element 'Page.Resources' in namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation' has invalid child element 'UserList' in namespace 'flashOfficerModel'. List of possible elements expected: 'ResourceDictionary.MergedDictionaries, ResourceDictionary.Source, ResourceDictionary.IsReadOnly, ResourceDictionary.Keys, ResourceDictionary.Values, sgObject, sgValueType, Point, Size, Vector, Rect, Matrix, Int32Rect, Duration, FontStyle, FontStretch, FontWeight, KeyTime, RepeatBehavior, Color, PixelFormat, Matrix3D, Point3D, Point4D, Quaternion, Rect3D, Size3D, Vector3D, CornerRadius, FigureLength, GridLength, Thickness, DependencyProperty, sgDispatcherObject, sgDependencyObject, sgFreezable, sgAnimatable, TextDecoration, TextDecorationCollection, sgTimeline, sgAnimationTimeline, sgDoubleAnimationBase, DoubleAnimationUsingPath, DoubleAnimation, DoubleAnimationUsingKeyFrames, sgBooleanAnimationBase, BooleanAnimationUsingKeyFrames, sgByteAnimationBase, ByteAnimation, ByteAnimationUsingKeyFrames, sgCharAnimationBase, CharAnimationUsingKeyFrames, sgColorAnimationBase, ColorAnimation, ColorAnimationUsingKeyFrames, sgDecimalAnimationBase, DecimalAnimation, DecimalAnimationUsingKeyFrames, sgInt16AnimationBase, .... D:\Projetos .NET 2.0\WPFCRM\flashOfficer\Home.xaml 9 8 flashOfficer

I do not know what is wrong since the class UserList is defined in the namespace flashOfficerModel. At the beggining of the code I have imported the namespace xmlns:local="flashOfficerModel".

What could be wrong

Thanks in advance



Re: Windows Presentation Foundation (WPF) Binding an ObservableCollection to a ListBox

eAlex79

Hi!

AFAIK the designer is not completed and gives this error because it does not know that your type may be declared at that point. Just ignore this WARNING (not error) and continue work Wink .

x
x Alex.
x





Re: Windows Presentation Foundation (WPF) Binding an ObservableCollection to a ListBox

Baffa

Hi Alex

It worked I have changed my XAML like this:

<Page x:Class="flashOfficer.Home"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="clr-namespace:flashOfficer"

Title="Home"

>

<Page x:Class="flashOfficer.Home"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="clr-namespace:flashOfficer"

Title="Home"

>

<Page.Resources>

<ObjectDataProvider x:Key="UserList" ObjectType="{x:Type local:UserList}" />

<Style TargetType="Hyperlink" x:Key="MainToolbarLink">

<Setter Property="FontSize" Value="12"/>

<Setter Property="FontWeight" Value="Normal"/>

<Setter Property="FontFamily" Value="Tahoma, Trebuchet MS, Arial"/>

<Setter Property="Foreground" Value="#012559"/>

</Style>

<DataTemplate x:Key="UserListTemplate">

<StackPanel Orientation="Horizontal">

<TextBlock Text="{Binding Path=userName}" />

<TextBlock Text=" " />

<TextBlock Text="{Binding Path=userEmail}" />

</StackPanel>

</DataTemplate>

</Page.Resources>

Thanks





Re: Windows Presentation Foundation (WPF) Binding an ObservableCollection to a ListBox

Laurent Bugnion

Hello,

You don't necessarily need an ObjectDataProvider to bind to your ObservableCollection. You can see an example at the link below. I tried to make the simplest possible example.

http://www.galasoft-lb.ch/mydotnet/articles/article-2007041201.aspx

HTH,
Laurent





Re: Windows Presentation Foundation (WPF) Binding an ObservableCollection to a ListBox

Baffa

Thanks Laurent

I have implemented a version with your solution, it worked fine.

I have another problem, maybe you can help me. I need to develop a XBAP that will bind information to SQL Server databases. This can be done directly ( ) or by using a WCF service. I am reading about WCF and XBAP and I have read that XBAP cannot access WCF Services, only .NET 3.5 will allow it and only OneWay services not binary.

Well this is not enough for me I will need duplex, or callback, services and binary messages to transfer large volume of data. I have been working with Flex for the last two years, so I have a good experience in developing SOA applications.

According to the articles and the books of WPF and WCF I have read I would need a Full trust XBAP to make it work. To make a XBAP Full trust I will need a setup procedure that I beleive is too much complicated for the average user. So I do not know exactly what to do, To develop a WPF Desktop application is possible but it will be the last option.

Can you help me. Can you give information or guide me to some literature that could allow me to implement a XBAP that is a tipical Internet Application with: File Upload and access to WCF services. I do not need to access services in other domains, just the doimain that the application was activated.

By the way you maintain a very good site, I have bookmarked it.

Thanks in advance





Re: Windows Presentation Foundation (WPF) Binding an ObservableCollection to a ListBox

Laurent Bugnion

Hi,

Thank you :-)

About your question: WCF will, as you found out, only be supported in partial trust in 3.5, coming probably later this year.

Now it's already possible to use WCF in an XBAP, but only in full trust, which I wouldn't recommend. Note also that even in 3.5, only HTTP bindings will be supported in partial trust.

My recommendation, for the moment, is to use ASMX web services from your XBAP to your web server. The actual SQL Server connection can be handled on the web server, and then return the values to the XBAP. ASMX web services can be used to communicate synchronously and asynchronously with the server of origin, and are probably your best (aka only) choice for the moment.

Greetings,
Laurent







Re: Windows Presentation Foundation (WPF) Binding an ObservableCollection to a ListBox

Baffa

Hi Laurent,

That's what I presumed would be the best choice. I am now working on a project that is not a public site, the service is very specific and I think I can develop a Full Trust XBAP.

It is very important that for Microsoft and for us that a urgent revision of the sandbox restrictions. Whith these restrictions is impossible to develop an Internet application with Presentation Foundation, only if you use WebServices. For large amount of data webservices this can be very inefficient.

Thanks you very much !!!!!