|
Hi All,
Does anyone have any tips on tracking down hard to find problems in XAML?
My application runs without any hitches and everything works as designed.
Blend opens the solution and displays the main window with out any errors or problems building the solution.
But VS2008 wont show the main screen in its XAML designer pane and says that there is an un-handled exception "Object reference not set to an instance of an object." I've seen this error and solved it before but the exception track trace gives no clue as to the source of the exception.
Thanks,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer,
1. build often so that things don't creep in.
2. I've seen this too. Blend likes this, VS doesn't. Also in the reverse.
3. To find your problem, open in VS and remove sections one at a time until the offending section is discovered. Then, go look at the constructors for code and controls in the offending section. You really need to watch code in your constructors as if it blows up, you get "REAL" misleading exception messages.
Hope this helps.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Yeah, i builld really often ... in fact almost constantly as I'm still really feeling my way around .NET in general.
I have a couple of ideas as to what might be doing it ... I need to investigate these. I think your idea of removing sections (do you mean controls and use controls?) will be a good one ...
Do you know of any plans by the WPF team to tighten the grip on XAML exceptions like this? I was chatting to another Developer at work today (a contractor) and he was expressing similar feelings about how difficult it can be to track down XAML problems.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer wrote: Do you know of any plans by the WPF team to tighten the grip on XAML exceptions
Have not heard of any specific rumblings, which is why I build often and learn the do's and don'ts. Comes with time, you'll get it all sorted out.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
For sure ... nothing beats experience.
I have my data loading and saving via my custom dialog now ... all looking very WPF and spanky new sparkly nice ...
Just trying to find out where the Serialization exceptions live now ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Unfortunately, the issue with the designer pane reporting an unhandled exception is consistent with the behaviour of the old WinForms designer. The problem actually relates to the designer having to "compile and interpret" the item in the designer, and some things just go wrong. I usually find that attempting a clean rebuild is a good idea in order to find issues.
|
|
|
|
|
Hi Pete,
A clean rebuild? Do you mean run a "Clean Solution" and then rebuild/recompile?
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer wrote:
A clean rebuild? Do you mean run a "Clean Solution" and then rebuild/recompile?
I certainly do.
|
|
|
|
|
Feck ... that didn't help at all. I need to sit down with more time for tackling this one.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
So I got inspired at work to learn WPF and Xaml. Cool technologies indeed, especially the data template stuff!
Anyway, I've been playing around with the TreeView control. I've successfully bound it to my data structure using the HierarchicalDataTemplate element. Now to my question: how do I propagate changes in my data to the control? Resetting the DataContext property to my data didn't do anything at all (which was expected - same reference being used!).
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
If you bind to an Observeable collection your changes will automatically be displayed.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Thanks! I will try it as soon as I get home.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Is there a rich text editor for silverlight, or will that be a 3rd party control?
|
|
|
|
|
Nope. No rich text editor. There's a marketing opportunity for you right there.
|
|
|
|
|
|
Hi,
I have two buttons on my WPF window when I click one I want to change the visibility of two layers in the screen. Problem is I can't see those layers in the intellisense.
Both the usercontrol navigator and the screen are in the same namespace. How do i 'find' the layer from the user control in order to change its visibility?
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer,
What do you mean by a layer? WPF does not have a layer control. What is the control type you are trying to hide or make visible? Does that control have a name assigned to it? When you assign a name to a control and rebuild the project, that control will show up in intellisense.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi Karl,
Its that old friend of ours d:IsLayer="True"
Basically In the user control (in the same namespace as the main presentation project not a separate UserControls namespace) I can't seem to 'see' any of the controls that are used in the main screen in order to change their visibility ... really odd.
And these controls have a x:Name="" ... should these be plain Name=""
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
x:Name is fine.
If you are in the code behind of a user control, you will not see the objects in the main window.
This encapsulation and separation of responsibilities is a feature of .NET and object oriented languages.
By having the user control address the controls on the main form you are creating a dependency inversion which "normally" we try to stay away from.
If the design of your application requires this you do have several options.
1. You can get a reference to the main window, then cast it to the type your main window is, then you can reference the controls on the main window.
2. You can have the user control raise an event that the the main window services and then allow the main window to set its controls.
3. You can expose properites on the user control that the main window can bind to, that controls their visibility.
4. You can pass a reference to the controls that the user control will effect in and then the user control can control them.
I'm sure there are other ways to accomplish this.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Thanks for this Karl. Loads more learning to do now! Not sure I even know how to cast something at the moment.
I'm still at the stage where I expect to be able do things that are simply daft, you shouldn't do or can't do at all.
hmm ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
What language to you use? C# or VB.NET?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
C# all the way ... I'm just trying this but it doesn't work yet ...
public sealed class ApplicationViewEventArgs : EventArgs
{
private Enums.ApplicationView _applicationView;
public Enums.ApplicationView ApplicationViewStatus
{
get
{
return _applicationView;
}
}
public ApplicationViewEventArgs(Enums.ApplicationView ApplicationViewStatus)
{
_applicationView = ApplicationViewStatus;
}
}
public partial class Navigator : UserControl
{
public delegate void ApplicationViewChanged(object sender, ApplicationViewEventArgs e);
public event ApplicationViewChanged ApplicationViewStatusChanged;
public Navigator()
{
InitializeComponent();
}
private void btnBrowseView_Click(object sender, RoutedEventArgs e)
{
if (ApplicationViewStatusChanged != null)
ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.BrowserView));
}
private void btnDatabaseView_Click(object sender, RoutedEventArgs e)
{
if (ApplicationViewStatusChanged != null)
ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.DataBaseView));
}
}
with this in my main window:
private void Navigator_ApplicationViewStatusChanged(object o, ApplicationViewEventArgs e)
{
lyrBrowserView.Visibility = Visibility.Hidden;
lyrDatabaseView.Visibility = Visibility.Hidden;
switch (e.ApplicationViewStatus)
{
case Enums.ApplicationView.BrowserView:
lyrBrowserView.Visibility = Visibility.Visible;
break;
case Enums.ApplicationView.DataBaseView:
lyrDatabaseView.Visibility = Visibility.Visible;
break;
}
}
the Enums look like:
public static class Enums
{
public enum ApplicationView
{
BrowserView = 0,
DataBaseView = 1,
ConfigurationView = 2
}
}
This is the first time I've even delt with events! Not going well ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I'm going to just spit out questions and comments, not in any order.
If you are swapping which user control is displayed, would a TabControl work better for you?
Is there a reason to put the buttons in a user control rather than just on the main form?
If you're using an event, you should use a RoutedEvent rather than a regular event in WPF. This way the child objects can bubble the event up the ElementTree.
Would a menu work for selection purposes?
There is another way to accomplish this also. You can use buttons in your user control that use RoutedCommands. In the button CommandParamenter load the ApplicationView enum value for that button. Then, set up a listener called CommandBinding in the main window. You can use one of the RoutedCommands supplied with WPF or create your own.
There are many articles on RoutedCommands here on Code Project. Suggest reading up on these. They enable decoupling of the command and the handler.
I also recently posted this on my blog: http://karlshifflett.wordpress.com/2008/02/24/wpf-sample-series-wpf-mvc-tabcontrol-mdi-and-commandbindings/[^]
modified 27-Feb-21 21:01pm.
|
|
|
|
|
I suppose any of those things are doable. I'm just swapping layers (or rather trying to swap layer visibility) I just wanted to put them in a user control in order to keep things tidy and it should be simple.
There is something i'm just totally missing in the code I posted. I like buttons more than menus too
Do you know why this isn't working?
public sealed class ApplicationViewEventArgs : EventArgs
{
private Enums.ApplicationView _applicationView;
public Enums.ApplicationView ApplicationViewStatus
{
get
{
return _applicationView;
}
}
public ApplicationViewEventArgs(Enums.ApplicationView ApplicationViewStatus) : base()
{
_applicationView = ApplicationViewStatus;
}
}
this is obviously the whole deal but its always returning null ... is there a "using System.blah" for events that I should be using?
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I don't see anything wrong, but my strength is VB.NET.
Maybe Pete can look at this for you.
Jammer wrote: this is obviously the whole deal but its always returning null
Not sure why these event args are null.
Did you set up an event handler for them in the main form?
Since you are new to WPF, you may want to take a step back and read up on RoutedCommands . This is the best solution for these buttons.
modified 27-Feb-21 21:01pm.
|
|
|
|