|
similar issue with me but I am not using silverlight
debugging a simple aspx page
|
|
|
|
|
akshayavat wrote: I am not using silverlight
debugging a simple aspx page
Then posting on the ASP.NET board would be more appropriate.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is it possible to dynamically load a usercontrol from a (.net) library?
|
|
|
|
|
All the "built-in" controls you use are dynamically loaded from libraries
so I'd say yes, it is possible.
Add a reference to the library, create an object of a public class that's
in the library, and go...
Or did you mean to ask something more specific?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark!
Thanks for the prompt answer!
I need to be more specific ...
When the (WPF) windows loads I want to load a UserControl from pos.dll for example.
How do you add dynamically controls in a WPF window ?
|
|
|
|
|
koyllis wrote: I want to load a UserControl from pos.dll for example.
Mark Salsbery wrote: Add a reference to the library, create an object of a public class that's
in the library, and go...
private void MyWindow_Loaded(object sender, RoutedEventArgs e)
{
MyUserControlNamespace.MyUserControl = new MyUserControlNamespace.MyUserControl();
...
< do something with the freshly loaded user control >
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I want to use Conditional Compilation Directives (#if, #endif) in my XAML file as well as in the codebehind file. Can anybody provide me links or sample code?
Is there any other technique to do the same? Please guide me.
ex.
#if TASK
<Button Click="AddTask">Add Task</Button>
#else
<Button Click="AddContact">Add Contact</Button>
#endif
|
|
|
|
|
You can only use the Conditional Compilation Directives in code behind. As you can see, they are not valid XML, so they are not suitable for use in XAML. From the look of the quick sample you've posted, you might want to use DataTemplates, Template Selectors and the MVVM pattern. Have a look at Josh Smith's article on MSDN to get a better understanding of this.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Can you please provide me the link?
|
|
|
|
|
I can do better than that - I can give you an idea of how I think, which hopefully means you can perform the same actions as me in future. This should mean that you don't have to wait for others to give you answers, instead you will be able to do your own research, saving you time, and increasing your effectiveness as a developer.
First of all, I thought to myself - how can I find the link to this article? I can't remember the URL of this article, but I can think of some mechanism which will allow me to look something up off the internet. So, once I've ascertained that I can't remember the URL directly, I know that I need to look it up from a search engine. At this point, I need to think of the keywords that will help me perform an effective search. Well, we know that the article was written by Josh Smith, we also know it was written for the MSDN magazine and it was about MVVM, so I can make an educated guess at the keywords; namely Josh Smith MVVM MSDN magazine. A quick hop on over to Google and I enter these keywords, hit search and what do you know, the first result is the one I want[^].
When you can think how to search for answers yourself, and not rely on others to do the searching for you, you will be able to make drastic leaps forward in your effectiveness and ability as a developer.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: Google
Here is an officialy recommended way to share Google links to your friends: http://lmgtfy.com/[^]
Yours sincerely -
- Google search engine development team
Greetings - Jacek
|
|
|
|
|
Jacek Gajek wrote: Here is an officialy recommended way to share Google links to your friends: http://lmgtfy.com/[^]
Give a man a fish, and he'll eat for a day.
Teach a man to fish, and he'll buy expensive rods and dodgy waders.
The moral of the story here - it's better to be the supplier to the person who teaches a man to fish; offer sufficient kickbacks and you'll never run out of business.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hey man thanks for your reply. However I googled and got the link before you give. I thought you could have given me the idea after searching Google. So the link could be recorded in your browser history. That could save time for me to search again.
However I am not looking for Routed Templates. I am looking for conditional Compilation in XAML, in which I can set the Parameters in the Project file and Include/Exclude some XAML output. I followed the article http://www.removingalldoubt.com/commentview.aspx/defa2a7d-b1e9-49eb-b8c8-438348be8d18[^] and solved the problem. I am posting this so that others can also refer to this solution.
|
|
|
|
|
Give a man a fish, and he'll eat for a day.
Turn a man into a fish, and he'll be eaten for the rest of his life.
|
|
|
|
|
In a SL 3 C# app there is a page named MainPage that contains a TabControl with some TabItems.
In the Page_Load event a user control is instantiated and added inside the MainPage's first TabItem.
For the sake of simplicity, the user control has only one button. I want to click this button and change the selected index of the TabControl .How?
To access the TabControl inside the MainPage directly I will need to create a static method but it will require the tabControls to be static as well and I definitely don't want to do that (Don't even know how).
Can someone show an example on how to access the MainPage's TabControl from inside the user control?
Thanks a lot!
|
|
|
|
|
I personally don't think a usercontrol should have intimate knowledge
of its parent tree so I would go with a different design - perhaps
add an event to the usercontrol that is raised when the button is clicked.
The parent of the usercontrol could subscribe to this event and handle the
tabcontrol appropriately.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark.
Would it be possible to post an example in C# 3.0 ? I have googled Delegate events but it has not been easy to find a good article about.
|
|
|
|
|
|
My previous question concerned dragging and dropping into a ListBox and the answer was in the Drop event I had to execute code like this:
Array a = (Array)e.Data.GetData(DataFormats.FileDrop);
The other part of this is that I have to set the AllowDrop property to true on the ListBox. All that works fine.
But then when we come to a TextBox, setting AllowDrop to True doesn't work. I drag text into the field and the cursor with the red slash through it persists when it enters the TextBox! I noticed the same thing months ago, but was busy with other things, so dropped the attempt to get dragging and dropping working into a TextBox. But when I got it working with a ListBox, I figured I now knew enough to get it working with a TextBox. No such luck! What am I missing?
Addendum: I just read that the WPF TextBox has drag and drop by default, and indeed dragging from one TextBox to another does work by default. But dragging and dropping from Windows Explorer to a WPF TextBox does not work whether or not AllowDrop is set to true, and that's precisely what I need. How can I get it?
modified on Friday, September 25, 2009 12:06 PM
|
|
|
|
|
As you have found, the TextBox (as well as RichTextBox and FlowDocument) marks drag and drop events as handled, which causes you real problems in cases like this. At first, you might think that this leaves you with a problem, but rejoice - WPF provides you with all that you need to do what you want.
The first thing that you need to do is modify the textbox to use certain preview events (PreviewDragEnter, PreviewDragOver and PreviewDragDrop) like so:
<TextBox
AllowDrop="True"
PreviewDragEnter="TextBox_PreviewDragOver" <-- Notice how this event
PreviewDragOver="TextBox_PreviewDragOver" <-- and this one map to the same event handler.
PreviewDrop="TextBox_PreviewDrop"/> Then, all you need to do is add the code for the events in the code behind:
private void TextBox_PreviewDragOver(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.All;
e.Handled = true;
}
private void TextBox_PreviewDrop(object sender, DragEventArgs e)
{
object text = e.Data.GetData(DataFormats.FileDrop);
TextBox tb = sender as TextBox;
if (tb != null)
{
tb.Text = string.Format("{0}",((string[])text)[0]);
}
} This sample simply picks the filename out and writes it to the textbox - you can do it with whatever you want. There, I hope that helps.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Excellent! I already had about 100 edit boxes scattered throughout my app that requires file paths and they all called a custom control I wrote, so modifying that single custom control got them all accepting drag and drop in five minutes!
I do wonder how people like you find answers like this. For example, where did you learn that you had to code those PreviewDrag events? And why do you use the PreviewDrop event and not just the Drop event? And what learning experience did you have to go through to realize that? What I'm trying to learn is the basis of your knowledge, because there's so many things about WPF that I don't seem to be able to figure out off the top of my head and have to Google for the answer, and my WPF app now has over 70,000 lines of C#/XAML code in it, which I've spent nine intense months developing (60+ hours per week). You'd think by now I'd be able to do it all, but I'm still puzzled by problems that crop up left and right. My work habits must be deficient in some way.
A specific question I have about your solution is that you get the standard mouse cursor with the plus sign inside a box when the drag operation enters the edit box. In my initial solution to the drop into a ListBox I got a mouse cursor with an empty box, not the box with the plus sign. By experimenting I determined that you achieve this with the code you have in the PreviewDrag events. What about that code gets you the cursor with the plus sign, avoiding that anemic cursor without the plus sign?
modified on Saturday, September 26, 2009 11:00 AM
|
|
|
|
|
fjparisIII wrote: What I'm trying to learn is the basis of your knowledge, because there's so many things about WPF that I don't seem to be able to figure out off the top of my head and have to Google for the answer, and my WPF app now has over 70,000 lines of C#/XAML code in it, which I've spent nine intense months developing (60+ hours per week). You'd think by now I'd be able to do it all, but I'm still puzzled by problems that crop up left and right. My work habits must be deficient in some way.
I'm lucky enough to be in regular contact and conversation with the likes of Josh Smith, Karl Shifflett, Sacha Barber and the likes through the WPF Disciples. It's not that your work habits are deficient - rather that the Disciples, eat, sleep and breathe WPF which means that you really start to investigate/think about the internals in depth. I've spent 2 years now, learning WPF to quite some degree, and at times I spend up to 100 hours a week working in WPF - I do it at work, and then go home and do it some more. This is just because the conversations we have in the Disciples can be so interesting, that intellectually you just don't want to give up.
Anyway, to answer your other question, I wrote a blog entry here[^] that might go some way towards answering your queries about the mouse cursor.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks very much for your reply. It explains a lot, and now I don't feel so inadequate. I have several books I consult, in addition to Googling all the time for answers and scouring MSDN and am still constantly blocked in my understanding of this and that within WPF. Also I've only been "at" this WPF thing for about a year (after doing C++/MFC since 1992 and STL since 2001).
Is there any way an outsider like myself can at least "listen in" on the conversations of the "Disciples"? Or is this some kind of private club for the "elite"?
|
|
|
|
|
fjparisIII wrote: Is there any way an outsider like myself can at least "listen in" on the conversations of the "Disciples"? Or is this some kind of private club for the "elite"?
If it were only for the elite, then I wouldn't be in it. It's a Google groups list, and you can find it here[^]. There's no reason to feel inadequate - a lot of the knowledge comes about the old fashioned way, discussing it with others and knocking the rough edges off ideas between yourselves.
If you're serious about WPF (and possibly Silverlight), you owe it to yourself to start looking into MVVM. Honestly, this pattern (while looking really confusing at first glance), simplifies a lot of what you can do in WPF. A lot of time, I don't bother with Attached Properties or Routed Events, I use MVVM and POCO (that's plain old clr objects), and it just fits into place.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I put my bid in to join the Disciples. Sounds like just the ticket for me.
I am interested in Silverlight, but I hardly even qualify as a beginner in Web development, even though I desperately need to develop some skills in it. I'm in the middle of reading one book on Silverlight, have ordered Matthew McDonald's yet to be published book on it, and so far am completely mystified about how it ties in with HTML. If I developed a Silverlight application, I wouldn't even know what to do with it.
But I recently bought Microsoft Expression Web 3 and that has some things in it about connecting to Silverlight applications. Maybe it will throw some light my way. Expression Blend is a little too pricy for my means.
|
|
|
|