|
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.
|
|
|
|
|
Hi Karl,
Thanks for that ... its weird isn't it ... i'm going backwards and forwards with this code and its just never getting evaluated and never grabbing the enums ... I have this in the main form that never gets called due to the if{} always being null ...
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;
}
}
I can't see anything i'm doing differently to any of the examples I'm finding online. I'm going to take a look at RoutedCommands I think. This is doing my head in ...
Thanks chap.
Pete, if you can shed any light on this I'll be forever in your debt!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer - sorry that it's taken so long for me to get to this. It's the first time I've been online in a couple of days. Have you actually hooked the event up to anything in the main form? If you want to send me the project (zipped up of course), I'll be more than happy to take a look at it.
|
|
|
|
|
Hey Pete,
Wow, that is an incredibly nice offer. I actually persisted and got my code working after some more head scratching. I was being extremely daft! I had given my user control an x:Name="" but only in the controls XAML file, not the main window XAML file where it is actually being instantiated. As soon as I'd done that all was well.
I'm just looking at some other UI code at the moment. I'm just in the process of building some new buttons and implementing some RoutedCommands.
Been quite a successful day of coding so far. I've practically finished a lot of the UI styling (using Blend) and I've implemented my first object serialization exercise ... bloody code worked first test! So my database is now persisted on disk! wooo ...
I'm loving C# ... XAML is still a tad confusing though.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
That's excellent. Sorry I couldn't get back to you earlier on this.
|
|
|
|
|
Not at all chap. You've been a great help!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Can the dreaded nullable combo-box be created in WPF. Of course with all the databinding enabled etc?
Seriously, I'm wondering why it hasn't already been done since this was a huge bug-bear with Windows Forms.
|
|
|
|