Custom Window
I am creating a custom window that looks similar to the Office 2007 UI. I was able to create an appropriate ControlTemplate/Style with dragging and "Close", Maximize/Minimize buttons etc... But here' the question: What's the best approach to have it encapculated in the separate class/component so I can easily re-use this style for other windows in the app?
[386 byte] By [
AlexY] at [2007-12-24]
You could put the template and style into the App's resources, without a x:Key, and set the TargetType to {x:Type Window} to make every window in the app automatically use that style. Is that what you're looking for?
Yeah... this is what I've done as well, but how do I go about events? For example, I have the LeftButtonDown events for 3 elements that are doing window dragging, closing and maximizing and in the App.xaml.cs we don't know about the window's instance.
Probably you can inherit your own Window class from the stock Window and use it everywhere.
P.S. Have you implemented window mouse resizing functionality as well? Does it works fine?
>Probably you can inherit your own Window class from the stock Window and use it everywhere.
I was thinking about that. Still trying to figure out how to declare XAML for the new window that inherits from my custom window. This is what I am doing:
<l:OfficeWindow x:Class="Lean360.Application.OfficeWindowControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:Lean360.Application"
>
<Grid>
</Grid>
</l:OfficeWindow>
where the OfficeWindow is my custom window. I am getting the warning:
"Could not find schema information for the element 'clr-namespace:Lean360.Application:HelpWindow'."
and the error:
'Lean360.Application.HelpWindow' cannot be the root of a XAML file because it was defined using XAML. Line 1 Position 15.
>Have you implemented window mouse resizing functionality as well? Does it works fine?
Not yet. I've got a few ideas how to do that, but still need to try it.
Alex, in v1.0 of WPF, you cannot subclass from a xaml generated class, probably this feature will be checked in in the v2.0.
Sheva
>I was thinking about that. Still trying to figure out how to declare XAML for the new window >that inherits from my custom window. This is what I am doing:
>[...]
Hm, HelpWindow sounds quite strange. If you didnt created it by yourself of course
. Here I can't imagine how to help without the whole project to look at.
> Not yet. I've got a few ideas how to do that, but still need to try it.
Ok. I just asked because I tried to implement custom resizing in Windows Forms. In certain places it is flickering hard, and I wasted this idea. But still it happened with a per-pixel transparent layered window, so with a normal one maybe it will be ok.
If to take into view the thing Footbalism wrote, I would rather write the base class code in a procedural manner. In context of WPF it is quite inconvinient, but at least it probably will work.
Yeah... IMO, this kinda defeats the whole XAML useability.
Well, Alex, one ulgy trick you can do here is that, you define the OfficeWindow class in the standalone assembly, and apply the following attribute: [assembly:XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation","Lean360.Application")] This can fool the XAML parser into believe that your custom OfficeWindow class is the built-in WPF class, then you can subclass from the OfficeWindow in xaml like following: <OfficeWindow x:Class="Lean360.Application.OfficeWindowControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid> </Grid> </OfficeWindow>
Anyway, this is the only way I can think of to overcome the restrictions, but the thing here is that Microsoft will probably sue you for using their copyright-protected xml namespace.
Sheva