|
John - why not use something like this[^]? It's simple and much more effective.
"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
|
|
|
|
|
Pardon my abruptness, but I've pretty much reached the end of my rope where WPF is concerned, so...
-------------
Because I didn't frakking know about templates, and there's really nothing I can find that presents the information COMPLETELY. All of the examples I've found assume I want to put frakking pictures in a listbox. I simply have strings thatI want to apply visual styles to based on certain criteria that I establish.
In WinForms, this took about 15 lines of code inside an event handler, and took me 20 minutes to figure out how to do. For WPF, it appears I have to write HUNDREDS of lines of code/XAML to do the same frakking thing, and I'v been trying to find a way to do it for TWO DAYS now! How the frak is this "better" than WinForms? Half-assed tools, requires twice the work on my part, and no frakking support from the anal pores that dreamed this steaming pile of horseshit up in the first place.
All I see is a bunch of half-brained ass-kissers running around with little WPF erections because they got it in their heads that this is somehow the end-all be-all of coding.
-------------
...even after that rant, I don't feel the slightest bit better. I'm just thoroughly pissed off.
I'm now off to look at the link you provided, but I'm really not confident that it will answer my questions nor provide even half of a solution.
I'm trying to convert my anagrams article to WPF. The Listbox is not bound to a collection. It accepts manually entered strings which are displayed in black (the default control color). When the user clicks a button, the strings that were already in the listbox are displayed in red, and all other possible strings are added and displayed in dark gray italics.
I'm not looking someone to code this for me - I just want to know how it's supposed to be done.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Well, I'm glad I gave you the chance to vent. When I started with WPF, I had pretty much the same reaction as you - it's taken me a long time to get to the point where it's second nature to me, and I know that it can be a pain.
Thing is though - if you stick with it, parts do fall into place - but you have to want to work with WPF in order to put that time in. If you don't want to work with it, don't - there are plenty of alternatives that don't require you to go through the "pain barrier".
"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
|
|
|
|
|
I guess the worst part is that I'm alone in my dissatisfaction with WPF here at work. Every time I run into something like this, it just pisses me off even more that we're even using WPF.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John - here's a simple application that you can use to test this type of functionality. I've added an ObservableCollection which consists of words that the user adds in via a textbox.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows;
namespace SampleWpfApplication
{
public class WordManager
{
public string Text { get; set; }
}
public class Words : ObservableCollection<WordManager>
{
}
public class WordTemplateSelector : DataTemplateSelector
{
public DataTemplate NormalWordTemplate { get; set; }
public DataTemplate RedWordTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
WordManager word = item as WordManager;
if (word.Text == "Howdy")
{
return RedWordTemplate;
}
else
{
return NormalWordTemplate;
}
}
}
} Here's the XAML that's used:
<Window x:Class="SampleWpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SampleWpfApplication"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="NormalWords">
<Grid>
<TextBlock Text="{Binding Path=Text}" Foreground="Brown"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="RedWords">
<TextBlock Text="{Binding Path=Text}" FontWeight="Bold" Foreground="Red"/>
</DataTemplate>
<local:Words x:Key="Words" />
<local:WordTemplateSelector
x:Key="TemplateSelector"
NormalWordTemplate="{StaticResource NormalWords}"
RedWordTemplate="{StaticResource RedWords}" />
</Window.Resources>
<StackPanel>
<ListBox x:Name="myList"
ItemsSource="{Binding Mode=Default, Source={StaticResource Words}}"
ItemTemplateSelector="{StaticResource TemplateSelector}"
x:FieldModifier="private"></ListBox>
<TextBox x:Name="myText" x:FieldModifier="private" Width="30" />
<Button Content="Click" Click="Button_Click" />
</StackPanel>
</Window> Finally, here's the button click code:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(myText.Text))
{
Words words = this.Resources["Words"] as Words;
if (words != null)
{
words.Add(new WordManager{Text=myText.Text});
}
}
} Basically the XAML is set up so that there can be multiple templates, which get applied based on certain conditions - chosen by the WordTemplateSelector class. By providing a template selector class, it's possible to add as many conditions as you like - all of which can have a simple template. The beauty of the approach here, is that we're using an ObservableCollection so that the template gets reevaluated whenever an item is added in. If you need more information, please feel free to ask.
"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
|
|
|
|
|
Well, it doesn't like part of the xaml stuff (I had implemented all of the stuff you showed before I saw your message). Here's what I have:
namespace AnagramsWPF
{
public class WordItem
{
public string Text { get; set; }
public bool Used { get; set; }
public WordItem(string text)
{
Text = text;
Used = false;
}
public override string ToString()
{
return Text;
}
}
public class WordTypeTemplateSelector : DataTemplateSelector
{
public DataTemplate UnusedWordTemplate { get; set; }
public DataTemplate UsedWordTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
WordItem wordItem = item as WordItem;
DataTemplate template = null;
if (wordItem.Used)
{
template = UsedWordTemplate;
}
else
{
template = UnusedWordTemplate;
}
return template;
}
}
}
In the xaml, I have this:
<Window.Resources>
<DataTemplate x:Key="unusedWord">
<Grid>
<TextBlock Text="{Binding Path=Text}" Foreground="DarkGray" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="usedWord">
<Grid>
<TextBlock Text="{Binding Path=Texe}" Foreground="Red" FontStyle="Italic" />
</Grid>
</DataTemplate>
<local:WordTypeTemplateSelector
x:Key="wordTypeTemplateSelector"
UsedWordTemplate="{StaticResource usedwordTemplate}"
UnusedWordTemplate="{StaticResource unusedwordTemplate}" />
</Window.Resources>
It doesn't like the underlined portion (it shows the error - "The type 'local:WordTypeTemplateSelector' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.").
I don't need the ObservableCollection stuff because the words are already in the collection before the user starts putting words into the listbox.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Tuesday, March 24, 2009 4:15 PM
|
|
|
|
|
You need to add this into your XAML to use the WordTypeTemplateSelector:
xmlns:local="clr-namespace:AnagramsWPF" If it's already present, build your application - this type of reference only works if there are no build errors that prevent that class being updated. I'm busy writing a WPFified version of CPAM and this might help to clarify things for you.
"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
|
|
|
|
|
Well, I got it to work, but it was a royal pain in the ass. It was a LOT simpler in WinForms.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Congratulations.
"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
|
|
|
|
|
I have to say I feel exactly the same. WPF is killing me - stuff which used to take a few lines of code can now take 100s of lines of code - even right aligning text in a listview is a pain and completely unobvious.
I used to spend about 20% of the time on the GUI and 80% on what the app actually did - that is now something like 50/50 and much of the WPF stuff is still a complete mystery - I used to be able to figure out most stuff for myself but now it's just lots of googling and hacking about with the answers I find until something looks similar to what I intended.
After all that the end product looks awful and is so slow on some PCs it's almost unusable. I have won industry awards for software written using Winforms - I won't be winning any using WPF.
|
|
|
|
|
Hello.
I'm working on an interface/front end for an application, my friend is working on the other half of the app which actually does the work. We're using this as a system to learn WPF better.
Anyhow, I have a canvas put aside which we wish to load his content into, but we can't figure out how. I've read that to load XAML into a Canvas you first need to parse it to a visual object, does this sound correct? Also, would it be easier if he created a user control which we could load into the canvas?
Regards, E.
|
|
|
|
|
What form will his project come in ? Why can't you just inject his XAML into your project, verbatim ?
Yes, having him create user controls seems like a good way for you to reuse them.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hello.
His project is a standard WPF app, a single XAML with code behind and an extra class to handle some more complex math.
He's created his app at a specific size, my app has a 'hole' in it the same size, currently filled by a canvas. I was wondering if I could load his XAML into the canvas?
Regards, E.
|
|
|
|
|
Hi
I m beginner in wpf application
Now i did the drag and drop using dependency property
The GUI class name is "Window1" but my drag and drop callback
method in "class1" class. The drag and drop are perfectly working
( Label drag and drop the the Uniform grid)
But now i need the label image (means the label preview) also
come with the mouse, when drag and drop. How we do this in Class1.
Then another one, the UniformGrid have 3 cell (for example).
Now want drag and drop the 3rd cell how can identify that cell
( if any build in methodology )
Then i want label drag over the first cell means that label image
visible in the first cell,
Please Help me.
Thank You
modified on Monday, March 23, 2009 7:04 AM
|
|
|
|
|
|
hi
I want to download file from the server. For this purpose i created a web service which returns a byte array of file. On silverlight page.xaml i got the byte array but how can i convert it to file so that i can save file to client hard disk.
If there is any other way to download file from server plz tell me.
Thanks in advance.
|
|
|
|
|
In Silverlight 2, the only access you have to the user's local hard disk
is using Isolated Storage:
Silverlight Isolated Storage[^]
Silverlight 3, now in beta, provides a save-file dialog that will allow the user
to select a place you can save the file to. Note that this will still require user
interaction - you won't be able to just write anywhere you want to.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
You can do it using a trick.
Instead of calling the web service, from Silverlight call javascript method that will make an open to a given URL, this URL will point to a custom HTTP handler, then you return your file (implementing a custom HTTP handler it's easy can send you some info or link), you only has to say that the file is an attachment.
In my case I just render e jpeg, js:
function showReportDiagramPopup() {
//http: //www.javascripter.net/faq/openinga.htm
window.open("DiagramRenderPopup.aspx", "DatabaseDiagram", "scrollbars=yes, width=800,height=600", false);
// NOT IN USE, rather using popup
// Finally we are not going to use a popup, we just open the generated image as an attachment
//window.location = "DiagramImageHandler.ashx"
}
In Silverlight:
public void ShowDiagramImageRenderPopup()
{
System.Windows.Browser.HtmlPage.Window.CreateInstance("showReportDiagramPopup");
}
HTH
Braulio
/// -------------------------
Braulio Díez
DBSchemaEditor.com
Free Silverlight based DB Schema Modeling Tool
/// -------------------------
|
|
|
|
|
It seems that RoutedEvent is quite similar with event. Is it true that we can do anything by event instead of RoutedEvent? If it is true, what is the advantage of RoutedEvent?
|
|
|
|
|
mildred-frontfree wrote: It seems that RoutedEvent is quite similar with event.
Which "event" are you referring to ?
Routed events are very powerful UI events. They are flexible enough to be placed at any place in the Element tree and handled by any other element. You can have a set of buttons and all the clicks handled at a common root. Also, there are scenarios like EventTriggers in XAML which only work with Routed events.
More information here[^]
|
|
|
|
|
Well, let me explain myself a little bit clear. On msdn there is a example like this.
<br />
public class MyButtonSimple: Button<br />
{<br />
public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent(<br />
"Tap", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyButtonSimple));<br />
<br />
public event RoutedEventHandler Tap<br />
{<br />
add { AddHandler(TapEvent, value); } <br />
remove { RemoveHandler(TapEvent, value); }<br />
}<br />
<br />
void RaiseTapEvent()<br />
{<br />
RoutedEventArgs newEventArgs = new RoutedEventArgs(MyButtonSimple.TapEvent);<br />
RaiseEvent(newEventArgs);<br />
}<br />
protected override void OnClick()<br />
{<br />
RaiseTapEvent();<br />
}<br />
<br />
}<br />
<br />
<br />
But, from my point of view, I could although done it this way
<br />
public delegate void DelegateClickEventHandler();<br />
public event DelegateClickEventHandler DelegateClickEvent;<br />
<br />
protected ovveride void OnClick()<br />
{<br />
if(DelegateClickEvent!=null)<br />
{<br />
DelegateClickEvent();<br />
}<br />
}<br />
And I could use this event in XAML either. So i am a little confused.
|
|
|
|
|
Routed events, cunningly enough, are designed to support event routing. Basically this mechanism allows you to register an event inside one element but, and this is the clever part, it can be raised by a completely different element. A simple example (and commonly quoted) is that a toolbar button click can go through the toolbar, then maybe a toolbar container, before finally being handled by your code. As you can see, this goes way beyond what you can manage with a simple event because the event would not bubble up in a traditional event scenario.
The problem you have here, is that the example on MSDN isn't terribly well explained, and the concept isn't clearly defined on the MSDN either.
"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
|
|
|
|
|
That was nicely explained That example on MSDN is pathetic and is more misleading than helping. When you read the explanation you somewhat get the picture but when you reach the example, it totally leaves you guessing into the behavior as of a normal event.
|
|
|
|
|
ABitSmart wrote: That was nicely explained
Thanks.
ABitSmart wrote: That example on MSDN is pathetic and is more misleading than helping.
Isn't it just? I really wish they'd up the quality of samples on MSDN. I used to rely heavily on MSDN - now, I tend to ignore it.
"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
|
|
|
|