Showing posts with label XAML. Show all posts
Showing posts with label XAML. Show all posts

Thursday, August 25, 2011

ListView column sorting

Found plenty of samples for WPF using a ListView and sorting on a column when the column header is clicked.
But I could not get any of them to work!!!
They never mentioned that this doesn't work with BindingList!!!
Switched to ObservableCollection<t>, and it worked fine.
I'm going to stop using that BindingList.

Russ

Wednesday, December 1, 2010

XAML and cryptic error message

Got the following cryptic error message when running a WPF application (a XamlParseException):
A 'Binding' cannot be used within a '<usercontrol>' collection. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
At first glance, everything looked good.  It might have been helpful if the error told me which property it was croaking on--but I guess MS can't learn to be specific with this XAML crap.  Fortunately, a quick google search and I stumbled onto a post where they identified thier problem when they got the same error: the owner in the DependencyProperty definition was not the control the property was on--changing it fixed their problem.  A second look at my code and I found I had done the same thing (the problem with cut-and-pasting).  Changing the owner type to the correct class fixed the problem.

Wednesday, October 27, 2010

XAML pages won't generate c# code behind on compile

You'd think Visual Studio would know that if a file ended in ".xaml", then the file.g.cs code that is supposed to be generated from the XAML on compile would always be generated.

Unfortunately for me, I had some significant refactoring to do.  I moved existing XAML files around into new projects, and found that I couldn't compile.  It took me awhile to figure out that the file.g.cs files weren't being generated.  Why they weren't didn't make sense, until a Google search turned up that the properties of these files must be set the Build Action to "page".  Apparently Visual Studio changed the Build Action to something else.  When set to "page", they generated the code correctly.

Tuesday, October 26, 2010

Referencing bitmap image file in XAML.

It was driving me nuts.  I wanted to put a bitmap file into a project as a resource and reference it from XAML in another project.  I Googled the web and followed all the directions, but nothing worked.  Everything always referred to a local bitmap or a XAML file.


I followed all the directions, but nothing worked.  Basically, this is what I had: Image.png was in Resource.csproj.  UI.csproj (in the same solution) had Page.xaml that needed to display Image.png.

I could get the solution to compile, but the image would never display.  I followed all instructions to the letter, but nothing worked.  I think they're all liers, out to get me.

I finally figured it out on my own.  What I figured out even goes against some explicit instruction from one of the sites.

First, in your resource project (Resource.csproj above), add a resource file (a file ending in ".resx"--I called mine "Images.resx").  Do not use the Resources that are part of the project properties, but instead add a separate resource file.

Now add your image to that resource file.  Select the image in the resources and on the properties, change the Persistence to "Embedded in .resx".

Finally, add the ImageSource in the Resources of your XAML. In my case, my example is:

<ImageSource x:key="MyImage">pack://application:,,,/Resource;component/Images/Image.png</ImageSource>

Note that the path to the image is the resource file I added.

[EDIT]
Looks like I spoke too soon.  I still had my image in a folder that matched the same path, located in the UI project ("/Images/Image.png").  When I deleted that image, it failed.  Well, when I figure it out--if I figure it out--I'll update this with the correct information.

Too bad no one else can give good information on this--I'd really like to know.

Thursday, December 3, 2009

XAML Binding to Datasets

Found that DataSets make lousy binds for WPF forms when the data must be updated from something other than directly by the user, because datasets do not implement INotifyPropertyChanged.

Datasets are great when the data is OneWay binding, because heirarchical data relationships are so easy to define. But you've got to get creative and use something else, such as a BindingList<> when the binding must be TwoWay or OneWayToSource.

Wednesday, December 2, 2009

XAML and the loss of Intellisense

Last week I reported losing my intellisense and tag completion on XAML pages.
 
I finally figured out the cause--and it's not good.  I happend to start up a new solution with a single page and all of a sudden I noticed I had my Intellisense and tag completion back!
 
After getting all excited about it, I went back to my original solution that was having problems--Intellisense and code completion disappeared.
 
Yet they came back with the nothing of a solution.
 
Okay--I get the hint.  XAML and WPF take lots and lots of RAM.  I have only 2GB.  From what I'm gathering, you need at least 3GB RAM.
 
All this only after I totally hosed up my Visual Studio trying to figure it all out.
 

Tuesday, December 1, 2009

Using Syncfusion

I'll give the support team at Syncfusion credit--they do seem to respond quickly to help you out.
 
But I'd give the development team there a failing grade.  They seem to be prone to deploy rather buggy controls for WPF use.
 
Seems getting "NullReferenceException" is commonplace with their controls.  And I just stumbled onto a stupid one--using their DateTimeEdit control and setting the MinDateTime attribute causes the control to display "01/01/0001" as its datetime value.  These kind of bugs are extremely annoying when you are trying to get a job done.  They're so bad that I don't know how they get away with charging for them when so many open-source and non-buggy alternatives are available.  Had I been give the ability to choose which controls to use, Syncfusion would never have been considered.
 
Fortunately, I stumbled onto http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117.  There is a DatePicker control there that'll work for me--and there's probably a large number of other controls.  Especially since Syncfusion is about as crappy as it comes--try finding what you need without asking their support department--I'm going to trash the Syncfusion control usage wherever possible.
 

Friday, November 27, 2009

Syncfusion GridDataControl and referencing other columns

I was using the Syncfusion GridDataControl in WPF and needed to reference a different column from within the column I was in, so that different attributes could be set based on other columns.  Found out from the SyncFusion Form support center that it's pretty easy.  Just set the Binding Path as follows:
 
Binding Path=Record.Data.OtherColumnName

WPF form and debugging data

I never realized just how painful it can be to debug data that should (or should not) display on a XAML form.  I bound a XAML form to a DataSet.  There was a problem with one of the columns in the dataset that caused problems with the XAML form.  But since there is no way to step through the debugger on the XAML, there was no way to figure out what the specific data was that was giving me problems.
 
The problem was solved through a Converter.  I discovered you can put a breakpoint on a converter, then view your data.  In my case, I had no need of a converter, so couldn't set up a breakpoint.
 
The solution was to add a special converter.  This one did not do any actual conversion--it simply returned the passed value.  But it gave me a simple way to put a breakpoint.
 
Below is the converter code:

class LogObjectDataConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
   
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}