开发者

Access methods of a class from a control template in a resource dictionary

I want to make a WindowBaseClass that derives from Window bu开发者_开发问答t has a few custom functionalities. Such that WindowStyle would be none, I have my own color scheme applied and also have a resize logic.

Here is a snippet of the XAML that contains one of the 'borders' that has a MouseMOve and PreviewMouseDown events.

<Rectangle Stroke="{x:Null}" x:Name="top" VerticalAlignment="Top" Height="5"
  Grid.Column="1" Grid.Row="0" PreviewMouseDown="Resize"
   MouseMove="DisplayResizeCursor">
                <Rectangle.Fill>
                    <SolidColorBrush Color="{StaticResource Ocean}"/>
                </Rectangle.Fill>

In my code behind I have methods such as resize, drag etc. When it is all contained in a Window1.xaml/.cs it's all working nice.

Now I want to create a custom template (in a resource dictionary for example) with my color schemes and I want the PreviewMouseDown from the rectangle to point to the method defined in a class that extends Window.

Can it be done? Any help would be greatly appreciated.


I don't think you'd approach it quite like that. I think you'd subclass Window and add in your custom PreviewMouseDown logic, etc. and then you would set up the styles for your new subclass in the resource dictionary.

You might also want to look into a custom attached property.

If PreviewMouseDown, etc. are doing logic specific to one window as opposed to general functionality, this probably isn't going to work out so great either way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜