 |
|
 |
I want to host controls within a ListBoxItem (ListBox control).Code XAML:
< ListBoxItem removed="LightBlue" Foreground="Blue" FontFamily="Verdana" FontSize="12" FontWeight="Bold"> < CheckBox Name="IcedTeaCheckBox"> "Horizontal"> < Image Source="temp.jpg" Height="30"></Image> < TextBlock Text="Iced Tea">< /TextBlock> StackPanel > CheckBox > ListBoxItem >
But i want to solve that by Coded-Behind. sorry for my english. Thank 
|
|
|
|
 |
|
 |
You want to add the controls in your code behind instead, or you want to access them there ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
 |
|
 |
Both Thank !
|
|
|
|
 |
|
 |
The listboxitem has AddChild and AddVisualChild methods. It also has a GetVisualChild method for getting back child elements. I'd say that's the way to go.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
 |
|
 |
I don't understand. Can't you give more detail ? Thank !
|
|
|
|
 |
|
 |
Not really, no. The methods are, IMO, self documenting. I've never done what you want to do, I just took the time to google it for you.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
 |
|
|
 |
|
 |
What are you having trouble with?
If you want to create controls from code, just create control objects and set properties on those objects.
e.g.
ListBoxItem item = new ListBoxItem(); item.Foreground = new SolidColorBrush(Colors.Blue); item.FontSize = 12; item.FontWeight = FontWeights.Bold; CheckBox cb = new CheckBox(); cb.Name = "IcedTeaCheckBox"; item.Content = cb;
Mark Salsbery Microsoft MVP - Visual C++
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
Hello everyone,
Is there any way I can create WCF web sevice from a wsdl? (not a proxy class from svcutil).
I know how to create one in normal way but when I createit manually , the WSDL file gets changed which I dont wont.
Thanks in advance,
Regards  , Nishu
|
|
|
|
 |
|
 |
If I understand the question correctly, then WSDL does not contain any code, so you cannot create WCF Service from WSDL. its just a description language, It is only useful for getting knowledge that, how you can call that web service. so you can generate method definition, but not method body.
|
|
|
|
 |
|
 |
Hi,
I have created a WPF IpAddressTextBox that inherits from System.Windows.Controls.Textbox. I want to initialize the textbox with the string " . . . " when the application starts. Everything works fine if I add the textbox to a testproject with the .xaml file with
<local:IpNumberTextbox Width="200" Margin="5"/>
But in the real project I add the textBox with
<controls:IpNumberTextbox Width="100" Text="{Binding SelectedItem.DNS1, ElementName = profilList }" />
In this project I have a Binding and when the dialogs shows up the textBox contains "" instead of " . . . ". In the debugger I can see that the TextBox Text property contains " . . . ", but the GUI is not updated. Why?
Regards Marcus
|
|
|
|
 |
|
 |
I would like to accept what is dropped from a drag operation of a selection of paths from Windows Explorer into a ListBox. I would think this would be pretty simple to do, but I can't find any examples that show how to do it. In my Drop event in the ListBox I have this line:
object text = e.Data.GetData(DataFormats.Text);
text comes back as null. How would I get at the list of files and folders dragged from Windows Explorer?
|
|
|
|
 |
|
 |
Try DataFormats.FileDrop, which will yield a string array of file names.
|
|
|
|
 |
|
 |
Thanks. After making my original post, shortly thereafter I did one more Google search and found the answer, but was still curious whether anyone would answer me so didn't mention it.
I was specifically interested in getting an array of file folders, since I can already get an array of file names with the normal WPF file browser, but can't get an array of file folders with the Shell's Folder Browser. Drag and Drop (and probably copy and paste) are the only ways to do that.
|
|
|
|
 |
|
 |
We have a wpf app developed under windows XP SP2. When this app runs under Vista, the text gets clipped in many places - it is as though a different font is used which is slightly larger.
I have seen this with both Tahoma and Arial.
I could go through and add padding or miniumum height to solve the, but it seems as though that should not be necessary (and may lead to other problems).
Has anyone else experienced this? Can anyone provide some advice or pointers?
A sample style is as follows:
<Style x:Key="Heading3" TargetType="{x:Type TextBlock}"> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="Foreground" Value="{DynamicResource textDimmedForegroundBrush}" /> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="FontFamily" Value="Arial"/> </Style>
Thanks for any help, Tim
|
|
|
|
 |
|
 |
I've had this happen, it's a real PITA. i suspect you can get around it by making sure you set the font size explicitly, but even then, I think the best thing to do is to make sure you test on both and that you provide space for both.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
 |
|
 |
Hi. I have a listview that im using its view property as grid. i want to have a grid with rows where each row has a textbox and a progressbar.
Ive created a class that have two members: a string member ans a progressbar member. I've created a collection object and added new instances of my class and then assigned the listview ItemsSource property to that collection.
but when displaying the listview in runtime i see instead of the progressbar the following text : "system.windows.controls.progressbar minimum maximum:10000 value ". I guess its because the itemTemplate of the listitem is text, but i dont know how to implement it.
here is the code :
private void Window_Loaded(object sender, RoutedEventArgs e) { System.Windows.Controls.ProgressBar p = new System.Windows.Controls.ProgressBar(); p.Maximum = 10000; p.Width = 100;
ObservableCollection<somesome> o = new ObservableCollection<somesome>(); o.Add(new somesome { text ="text" , pro = p }); listView1.ItemsSource = o; }
public class somesome { public string text { get; set; } public System.Windows.Controls.ProgressBar pro { get; set; } }
Thanks for advance.
|
|
|
|
 |
|
 |
Hi, I am creating a plug-in DLL for a piece of software using C#, the plug-in launches a very basic WCF self hosted service. The WCF contract and launching code are both almost identical to the MSDN basic service tutorial. Here
The problem that I am having is that when I click on the URL that the service is bound to, nothing happens, I know that the browser has connected to the service but eventually times out.
In order to test the DLL I have created a simple console app, the app loads the DLL and launches the service without any problem, so my code is fine.
I have come to the conclusion that the host that loads the DLL is somehow blocking the WCF service, does anybody know how this is possible?
Is it possible to block WCF through trace listeners? or similar debugging methods?
Thank you very much
|
|
|
|
 |