Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting objects on a WPF canvas?
Message
De
27/02/2009 04:44:51
 
 
À
26/02/2009 13:48:39
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01383557
Message ID:
01384473
Vues:
37
>>If you want the style to apply to all HolePattern objects (and only HolePattern objects or sub-classes) you can achieve this just in XAML. Make 'HolePattern' the TargetType and omit the x:Key attribute. The style will then be applied to all HolePattern objects regardless of how or when they are added to the Canvas.
>>HTH,
>>Viv
>
>Well, I've used blanketing styles in other places in my XAML to dynamically build the UI based on the active HolePattern. So, that's cool to also realize how it could be automatically assigned to every Ellipse in the window in the same manner.
>
>However, let me make sure I understand something, becuase what you sugessted above does not work...
>
>In the app, I have 2 custom classes that make up the main working architecture of the thing... HolePattern, and Hole. So, HolePattern is a collection of Holes, and each of these are custom classes, and neither is a Shape base class, but the Hole class does have a Shape object as a member field, and that Ellipse shape is what I work from for populating the canvas.
>
>So, you said target 'HolePattern', (but I think you meant 'Hole'), but even then, I do not think it will work, as those are not visual Shape classes.
>
>HolePattern (custom class), has a collection member that contains a list of Hole class objects
> +--- Hole (custom class) a single hole
> +--- Ellipse (a Shape object on the Hole that can be added to a Canvas) --------- Must apply style to this
>
>Am I right? I type in Hole and HolePattern in the XAML, and even the pre-compiler complained about not being able to resolve it. I think the TargetType has to remain Ellipse. Maybe you though Hole was a Shape class, and in that case I bet it would would work.

You're right. I did mean Hole and, for no reason, assumed it was a suitable class The class has to support the Style property which means deriving from FrameworkElement (or FrameworkContentElement) and, of course, have dependency properties for any property defined in the Style.
So you could set the style globally on the Ellipse class - but that's probably too wide a scope. You could, however, put the style in the Canvas.Resources collection so that it would only apply to Ellipses within the canvas.
Another alternative might be to derive Hole from, say, UserControl and embed an ellipse with it's own style inside - but that might be too dispruptive given your existing code......

>By the way, I have posted the source code for this up on CodePlex, so you can download the source zip file from there, and see the current screenshot. When you get time to download and run it, please let me know what think. Be sure to read the Project Description so you'll see the plug I gave you for helping me out.
>
>http://www.codeplex.com/WPFHolePatterns

Thanks for the link. I'll try to get it sometime today,
Regards,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform