c# - custom button in wpf with path as content -


how can create custom button control takes argument of path in button constructor can reuse control throughout projects?

this how create buttons....

<grid>     <button style="{dynamicresource buttonpathstyle}" width="24" height="24">         <path fill="gray" data="m50,50 l100,100 l150,50" stretch="uniform" />     </button> </grid> 

however create custom button create them along custom style sheet

<grid>     <pathbutton width="24" height="24"                 data="m50,50 l100,100 l150,50"                   stretch="uniform" /> </grid> 

if knows of resources of can whip quick example it'd appreciated. assume creating button pretty simple custom control.

and custom control mean compile dll can share.

code behind:

    public class pathbutton : button {     public static dependencyproperty dataproperty = dependencyproperty.register("data", typeof(geometry), typeof(pathbutton), new frameworkpropertymetadata(new propertychangedcallback(data_changed)));      public geometry data     {         { return (geometry)getvalue(dataproperty); }         set { setvalue(dataproperty, value); }     }      private static void data_changed(dependencyobject o, dependencypropertychangedeventargs args)     {         pathbutton thisclass = (pathbutton)o;         thisclass.setdata();     }      private void setdata()     {         path path = new path();         path.data = data;         path.stroke = this.foreground;         path.strokethickness = 1;         this.content = path;     } } 

xaml:

<window x:class="wpfapplication2.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns:local="clr-namespace:wpfapplication2"     mc:ignorable="d"     title="mainwindow" height="350" width="525"> <grid>     <local:pathbutton data="m50,50 l100,100 l150,50" /> </grid> 


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -