Reference Access database dataset.designer file in WPF? - wpf

Hey, I've included an MS Access database in my WPF VB app, and I'm trying to link the data to an XCEED Datagrid. I have the following code in my testerDataSet.Designer.vb file which I assume is the funcion I should be referencing
Public ReadOnly Property Contact() As ContactDataTable
Get
Return Me.tableContact
End Get
End Property
I'm trying to get it to fill my datagirid using this
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_contacts" Source="{Binding Path=Contact, *Source={x:Static testerDataSet}*}"/>
</Grid.Resources>
<xcdg:DataGridControl Margin="54,18,4,3" Name="DataGridControl1" ItemsSource="{Binding Source={StaticResource cvs_contacts}}"/>
Unfortunately the bolded/stared part is givi ng me errors, does anyone know the correct code i should be using here to reference my source?
Thanks guys!
EDIT: Okay let me try and outline what I've done... I've added an Access 2007 Database called "tester" to my project as an existing item, and VS has gone and made testerDataSet for me, and inside testerDataset.Designer.vb I assume the first code above is the code i need to display my table data.
Basically my entire code for Window1.xaml is as follows (its just a test project to see If I can actually get the database working)
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="369" Width="503" xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
<Grid>
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_contacts" Source="{Binding Path=Contact, Source={StaticResource testerDataSet}}"/>
</Grid.Resources>
<xcdg:DataGridControl Margin="54,18,4,3" Name="DataGridControl1" ItemsSource="{Binding Source={StaticResource cvs_contacts}}"/>
</Grid>
What I'm trying to achieve is for the datagrid to display the data in the Contact datatable. I'm probably missing something important here (I'm quite new to coding =/ ) To be perfectly honest I've had a hard time finding appropriate tutorials for this so I'm not entirely sure what I'm doing
THanks again

Can you update your sample to include the code for the static resource testerDataSet?
One way you can try and work around this problem is to set the Binding directly in imperative code.
DataGridControl1.DataContext = testerDataSet.Contact
Then you could modify your WPF code to be the following
<xcdg:DataGridControl
Margin="54,18,4,3"
Name="DataGridControl1"
ItemsSource="{Binding}" />
That may not be 100% what you're looking for but it should at least temporarily unblock you.

Related

"Prefix '....' does not map to a namespace", A designer bug?

My application runs and works absolutely fine. Now I want to use the VS2012 designer to design my MainWindow which is derived type of the HandledWindow from a different library.
Here is my XAML code for MainWindow:
<UI:HandledWindow x:Class="Diamond.Executor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UI="clr-namespace:Diamond.Core.UI;assembly=Diamond.Core"
Title="MainWindow"
Height="250"
Width="500"
Style="{DynamicResource WindowStandard}"
WindowStartupLocation="CenterScreen"
Loaded="Initialise">
Here is where base type HandledWindow:
namespace Diamond.Core.UI
{
public class HandledWindow : Window
{
What is wrong here? When I run my application anything works, the bindings, The style and it's template.
But suddenly the designer says "'UI' doesn't map to a namespace". I just don't get it. It stops my development really without a reason. Perhaps a VS2012 bug, But I want to insure I am doing everything right and if there is a way to pass that bug and continue using the designer?
I've discovered what just causes the issue, But I don't know why, Because by syntax it's okay and logically it works. But XAML's desginer fails to work properly with such data binding expression:
FontSize="{Binding Path=(UI:HandledWindow.FontSizeTitle), Mode=OneWay}"
(It's part of a style inside the UI namespace that XAML declined in a whole because of this expression)
Then I've changed it to this expression:
FontSize="{Binding FontSizeTitle, RelativeSource={RelativeSource TemplatedParent}}"
It does exactly the same, But now the XAML designer works again and stops ignoring the whole namespace UI because of a single data binding expression.
Anyway, The issue is finally resolved.

Cross DomainDataSource Combobox SelectedItem Binding

I'm fairly new to Data binding & XAML, so this probably is fairly simple thing but I've been stumped on it for days now (and frustrated with more googling than i can track at this point) and would appreciate any pointers in the right direction. My only preference is to keep it in pure XAML if possible.
In my RIA SL4 project, I have two Entities PackageOS and OS where PackageOS has an association to OS through PackageOS.OS (associating through PackageOS.OSID <-> OS.ID - and [Include] + .Include() setup properly on relevant sections)
This is the template (defined in Page.Resource section along with all other involved DDS) I'm using in DataForm to get OSEntities List to bind into PackageOS Entity (coming from RIA GetOSEntities() using DDS):
<DataTemplate x:Key="POSItemTemplate">
<StackPanel>
<toolkit:DataField Label="PackageOS.OS">
<TextBlock Text="{Binding Source={StaticResource packageOSEntityDomainDataSource}, Path=Data.CurrentItem.OS}" />
</toolkit:DataField>
<toolkit:DataField Label="OS">
<ComboBox ItemsSource="{Binding Path=Data, Source={StaticResource osEntityDomainDataSource}}"
SelectedItem="{Binding Path=Data.CurrentItem.OS, Source={StaticResource packageOSEntityDomainDataSource}}"/>
</toolkit:DataField>
</StackPanel>
</DataTemplate>
The core problem is SelectedItem of ComboBox is not working. All the bindings are reachable from IDE Binding wizard so it's not a problem of me typing incorrect path. I can see packageOSEntityDomainDataSource.Data.CurrentItem to be of type PackageOS.
If i create a manual entry in backend database, the result is shown in PackageOS.OS textblock so I know it is properly being returned but SelectedItem refuses to pick it up (it ends up selecting the first value in dropdown list regardless of OS item in PackageOS).
Many thanks in advance!
Finally figured this out. Leaving my answer in hopes that it saves somebody else the time that I spent on this.
First Lesson
The problem was in the fact that I didn't have a custom Equality implementation for generated entities and default reference equality didn't work as I was using two different instances. Once I implemented IEquatable on my generated entities (through .shared.cs partial classes on server side) everything started working like a charm.
For details please see Silverlight ComboBox Control Population by Manishdalal
Second lesson
Do not use multiple DDS controls if you can help it. Especially once you use a write operation on a DDS, you cannot load/refresh any other DDS that is sharing the DomainContext until changes are committed. The link above shows how to avoid multiple DDS by using list generators when all you want is to pick up list of entities to fill ComboBox up.
My new code looks like this:
<DataTemplate x:Key="POSItemTemplate">
<StackPanel d:DataContext="{Binding Source=packageOSDomainDataSource, Path=Data.CurrentItem}">
<toolkit:DataField Label="OS">
<ComboBox DisplayMemberPath="Name"
ItemsSource="{Binding Path=OSList, Source={StaticResource OSListGenerator}}"
SelectedItem="{Binding Path=OS, Mode=TwoWay}" />
</toolkit:DataField>
</StackPanel>
</DataTemplate>
Where OSListGenerator is returning an IEnumerable<OSEntity> through its OSList property after loading it from DomainContext
Third Lesson
In DDS DataTemplate you have to be explicit with TwoWay Binding. This is the new behaviour; something that took me days to figure as most of the tutorials I referred to were using SL3 and I didn't realize that this was a breaking change in DDS DataTemplate behaviour in SL4.

Dynamic Binding for Settings?

I am facing a problem, I have a application with several setting's files but which have exactly the same fields.
Sample :
Profil1.settings
Profil2.settings
Profil3.settings
What I'd like to do in my setting window XAML is to dynamicaly change the binding source for each profile.
At the moment my XAML binding look like this :
SelectedValue="{Binding Source={x:Static Local:Properties.Profil1.Default}, Path=CurrentProfil, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
My problem is how to replace the "Profil1" by "Profil2" without remaking all my Binding one by one for each controls via my code behind ? Is that possible to use some king of reflection variable in the XAML binding source and than simply change the type of that variable with Profil1 type or Profil2 type ?
Anyone can help me about this ?
Thank in advance.
What you want to do is set the DataContext of your settings window to the appropriate profile. You can do it anyway you want, but by doing so, all your bindings would point to that object. To make the bindings work like you have now, you'd do:
<Window x:Class="MyNamespace.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Local="clr-namespace:MyNamespace"
DataContext="{Binding Source={x:Static Local:Properties.Profil1.Default}}">
...
<ComboBox SelectedValue="{Binding Path=CurrentProfil, Mode=TwoWay, UpdateSourceTrigger=Explicit}" />

WPF Databinding to Custom Collection Objects

Public Sub New(ByVal log As Entities.LogSystem)
InitializeComponent()
Me.DataContext = log
End Sub
This is the the initializer for my custom control It passes in a single entity that has several property fields. This control is added to a parent control so that it appears in a stackpanel.
Anyway I am trying to get the specific data from this control into several different text boxes:
<UserControl x:Class="LogSystemPickerItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WavelengthIS.WISRED.UserControls"
Width="579" Height="122">
<UserControl.Resources>
<local:LogSystemPickerItem x:Key="Log"/>
</UserControl.Resources>
<Grid DataContext="{Binding Source={StaticResource Log}}">
<Label Height="30" Name="Label1" VerticalAlignment="Top" Content="{Binding deptDescription}"/>
</Grid>
</UserControl>
As you can see i havent really gotten too far. I have tried many different ways to do this including using dependency properties...I just really cant find a tutorial that shows this specific circumstance...can anyone point me in the right direction?
If you're setting the DataContext in the code behind as per your first code snippet, there's no need to also do it in the XAML, so you can remove the "Log" resource and the corresponding DataContext assignment on the Grid.
Once you've done that, it should work assuming there is a deptDescription property on your log class.
... and in XAML you may do it this way...
<UserControl.DataContext>
<local:LogSystemPickerItem/>
</UserControl.DataContext>

XamlParseException when databinding a ComboBox to a statically-defined array in XAML

I've been trying to solve this problem for over an hour now, and can't figure it out. Hopefully someone can see what I'm doing wrong.
I have two separate projects, both of which populate a combobox with an array of Doubles in the UserControl.Resources section, then databind to it in the GUI. What I'm doing is essentially just this, which works fine in kaxaml and in one of my two projects.
<Page>
<Page.Resources>
<x:Array x:Key="Increments" Type="sys:Double">
<sys:Double>0.01</sys:Double>
<sys:Double>0.02</sys:Double>
<sys:Double>0.03</sys:Double>
<sys:Double>0.04</sys:Double>
</x:Array>
</Page.Resources>
<Grid>
<ComboBox ItemsSource="{StaticResource Increments}" />
</Grid>
</Page>
The other project gives me the following error:
Cannot convert the value in attribute
'ItemsSource' to object of type
'System.Collections.IEnumerable'.
'System.Windows.Markup.ArrayExtension'
is not a valid value for property
'ItemsSource'. Error at object
'System.Windows.Controls.ComboBox' in
markup file ...
I cannot figure out why this is happening. I've tried looking at the schemas referenced in both XAML files, but they are the same... I don't have any errors or messages in the Output window. I got desperate and ran it through FxCop to see if it would catch something related, and although it has caught several valid errors, none of them were related.
I had to wrap this in an ObjectDataProvider to get it to work, and replace the StaticResource with a binding to the StaticResource:
<!-- Resources -->
<ObjectDataProvider x:Key="Incs2">
<ObjectDataProvider.ObjectInstance>
<x:Array Type="sys:Double">
<sys:Double>0.01</sys:Double>
<sys:Double>0.02</sys:Double>
<sys:Double>0.03</sys:Double>
<sys:Double>0.04</sys:Double>
</x:Array>
</ObjectDataProvider.ObjectInstance>
</ObjectDataProvider>
<!-- Page content -->
<ComboBox ItemsSource="{Binding Source={StaticResource Incs2}}" />
EDIT: I've also found that if I move the x:Array resource to the top of my Resources section, before any other resource declaration, I can use your original ItemsSource="{StaticResource ...}" and I no longer get the exception (or need the ObjectDataProvider). This would seem to be a bug in WPF.

Resources