messagebox - WPF transparent message box -


is possible add custom styling messagebox?

messagebox.show("bla bla", "error"); 

i want change of window. options?

this create custom message box

 background="transparent" closing="messageboxwindow_closing"         loaded="window_loaded" rendertransformorigin="0.5, 0.5"         resizemode="noresize" showintaskbar="false"         sizetocontent="widthandheight"          windowstartuplocation="centerowner" windowstyle="none">     <window.rendertransform>         <scaletransform x:name="scale"/>     </window.rendertransform>     <window.resources>          <lineargradientbrush x:key="backgroundbrush" startpoint="0,0" endpoint="0,1">             <gradientstop offset="0" color="#e4e9f0"/>             <gradientstop offset="1" color="#d5dded"/>         </lineargradientbrush>          <style targettype="label">             <setter property="verticalcontentalignment" value="center"/>             <setter property="horizontalcontentalignment" value="left"/>             <setter property="fontfamily" value="segoe ui"/>             <setter property="fontsize" value="12pt"/>             <setter property="foreground" value="#ff003399"/>         </style>         <style targettype="image">             <setter property="height" value="32"/>             <setter property="width" value="32"/>             <setter property="margin" value="3"/>         </style>          <storyboard x:key="loadanimation">             <doubleanimation accelerationratio="0.4" duration="00:00:00.15" from="0.6" storyboard.targetname="scale" storyboard.targetproperty="(scaletransform.scalex)" to="1.1"/>             <doubleanimation accelerationratio="0.4" duration="00:00:00.15" from="0.6" storyboard.targetname="scale" storyboard.targetproperty="(scaletransform.scaley)" to="1.1"/>             <doubleanimation accelerationratio="0.4" duration="00:00:00.15" from="0" storyboard.targetname="messageboxwindow" storyboard.targetproperty="(window.opacity)" to="1"/>             <doubleanimation begintime="00:00:00.15" duration="00:00:00.1" from="1.1" storyboard.targetname="scale" storyboard.targetproperty="(scaletransform.scalex)" to="1"/>             <doubleanimation begintime="00:00:00.15" duration="00:00:00.1" from="1.1" storyboard.targetname="scale" storyboard.targetproperty="(scaletransform.scaley)" to="1"/>         </storyboard>          <storyboard x:key="unloadanimation">             <doubleanimation accelerationratio="0.4" duration="00:00:00.2" from="1" storyboard.targetname="scale"  storyboard.targetproperty="(scaletransform.scalex)" to="0.6"/>             <doubleanimation accelerationratio="0.4" duration="00:00:00.2" from="1" storyboard.targetname="scale" storyboard.targetproperty="(scaletransform.scaley)" to="0.6"/>             <doubleanimation accelerationratio="0.4" duration="00:00:00.2" from="1" storyboard.targetname="messageboxwindow" storyboard.targetproperty="(window.opacity)" to="0"/>         </storyboard>          <style  targettype="{x:type button}">             <setter property="fontsize" value="15"/>             <setter property="width" value="124"/>             <setter property="height" value="42"/>             <setter property="foreground" value="white"/>             <setter property="template">                 <setter.value>                     <controltemplate targettype="{x:type button}">                         <grid>                             <image x:name="cancelbutton" source="pack://application:,,,/v-coles;component/resources/images/openlockerbtn.png" />                             <contentpresenter x:name="contentpresenter" focusable="false" horizontalalignment="{templatebinding horizontalcontentalignment}" margin="{templatebinding padding}" recognizesaccesskey="true" snapstodevicepixels="{templatebinding snapstodevicepixels}" verticalalignment="{templatebinding verticalcontentalignment}"/>                         </grid>                         <controltemplate.triggers>                             <trigger property="isdefaulted" value="true">                             </trigger>                             <trigger property="ismouseover" value="true">                                 <setter property="source" targetname="cancelbutton" value="pack://application:,,,/v-coles;component/resources/images/openlockerbtnhover.png"/>                             </trigger>                             <trigger property="ispressed" value="true">                                 <setter property="source" targetname="cancelbutton" value="pack://application:,,,/v-coles;component/resources/images/openlockerbtnhover.png"/>                             </trigger>                             <trigger property="isenabled" value="false">                             </trigger>                         </controltemplate.triggers>                     </controltemplate>                 </setter.value>             </setter>         </style>      </window.resources>     <border height="150" width="300" background="#dd4739" padding="7" margin="50,100,50,50">         <dockpanel lastchildfill="true">             <stackpanel x:name="buttonspanel" horizontalalignment="center" dockpanel.dock="bottom" orientation="horizontal"/>             <image x:name="imageplaceholder" dockpanel.dock="left"/>             <label x:name="messagelabel" dockpanel.dock="right">                 <textblock x:name="messagetext" foreground="black" textwrapping="wrap"/>             </label>         </dockpanel>     </border> </window>   public partial class messagebox : inotifypropertychanged     {         #region private field           private bool _animationran;          #endregion          #region constructor           public messagebox(window owner, string message, string details, messageboxbutton button, messageboximage icon, messageboxresult defaultresult, messageboxoptions options)         {             this._animationran = false;              this.initializecomponent();              owner = owner ?? application.current.mainwindow;              this.createbuttons(button, defaultresult);              this.createimage(icon);              messagetext.text = message;              this.applyoptions(options);         }          #endregion          #region event property           public event propertychangedeventhandler propertychanged;          #endregion          #region public property          /// <summary>         /// gets or sets value indicating whether isactivemessagebox         /// </summary>         public static bool isactivemessagebox { get; set; }           public static window activemessagebox { get; set; }           public messageboxresult messageboxresult { get; set; }          #endregion          #region public static method           public static messageboxresult showinformation(string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return showinformation(null, message, details, showcancel, options);         }           public static messageboxresult showinformation(window owner, string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return show(owner, message, details, showcancel ? messageboxbutton.okcancel : messageboxbutton.ok, messageboximage.information, messageboxresult.ok, options);         }           public static messageboxresult showquestion(string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return showquestion(null, message, details, showcancel, options);         }           public static messageboxresult showquestion(window owner, string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return show(owner, message, details, showcancel ? messageboxbutton.yesnocancel : messageboxbutton.yesno, messageboximage.question, messageboxresult.yes, options);         }           public static messageboxresult showwarning(string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return showwarning(null, message, details, showcancel, options);         }           public static messageboxresult showwarning(window owner, string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return show(owner, message, details, showcancel ? messageboxbutton.okcancel : messageboxbutton.ok, messageboximage.warning, messageboxresult.ok, options);         }           public static messageboxresult showerror(exception exception, string message = "", messageboxoptions options = messageboxoptions.none)         {             return showerror(null, exception, message, options);         }           public static messageboxresult showerror(string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return showerror(null, message, details, showcancel, options);         }           public static messageboxresult showerror(window owner, exception exception, string message = "", messageboxoptions options = messageboxoptions.none)         {             string details = string.empty; #if debug             details = exception.tostring(); #endif             return show(owner, string.isnullorempty(message) ? exception.message : message, details, messageboxbutton.ok, messageboximage.error, messageboxresult.ok, options);         }           public static messageboxresult showerror(window owner, string message, string details = "", bool showcancel = false, messageboxoptions options = messageboxoptions.none)         {             return show(owner, message, details, showcancel ? messageboxbutton.okcancel : messageboxbutton.ok, messageboximage.error, messageboxresult.ok, options);         }           public static messageboxresult show(string message, string details = "", messageboxbutton button = messageboxbutton.ok, messageboximage icon = messageboximage.none, messageboxresult defaultresult = messageboxresult.none, messageboxoptions options = messageboxoptions.none)         {             return show(null, message, details, button, icon, defaultresult, options);         }           public static messageboxresult show(string message, messageboxbutton button = messageboxbutton.ok, messageboximage icon = messageboximage.none, messageboxresult defaultresult = messageboxresult.none, messageboxoptions options = messageboxoptions.none)         {             return show(message, string.empty, button, icon, defaultresult, options);         }           public static messageboxresult show(window owner, string message, messageboxbutton button = messageboxbutton.ok, messageboximage icon = messageboximage.none, messageboxresult defaultresult = messageboxresult.none, messageboxoptions options = messageboxoptions.none)         {             return show(owner, message, string.empty, button, icon, defaultresult, options);         }           public static messageboxresult show(window owner, string message, string details = "", messageboxbutton button = messageboxbutton.ok, messageboximage icon = messageboximage.none, messageboxresult defaultresult = messageboxresult.none, messageboxoptions options = messageboxoptions.none)         {             messageboxresult result = messageboxresult.none;             result = application.current.dispatcher.invoke(new func<messageboxresult>(() =>             {                 var messagebox = new messagebox(owner, message, details, button, icon, defaultresult, options);                 isactivemessagebox = true;                 activemessagebox = messagebox;                 messagebox.showdialog();                  return messagebox.messageboxresult;             }));              if (result != messageboxresult.none)             {                 return (messageboxresult)result;             }             else             {                 return messageboxresult.none;             }         }          #endregion          #region public method           public void onpropertychanged(string propertyname)         {             propertychangedeventhandler temp = this.propertychanged;             if (temp != null)             {                 temp(this, new propertychangedeventargs(propertyname));             }         }          #endregion          #region private method           private void createbuttons(messageboxbutton button, messageboxresult defaultresult)         {             switch (button)             {                 case messageboxbutton.ok:                     buttonspanel.children.add(this.createokbutton(defaultresult));                     break;                 case messageboxbutton.okcancel:                     buttonspanel.children.add(this.createokbutton(defaultresult));                     buttonspanel.children.add(this.createcancelbutton(defaultresult));                     break;                 case messageboxbutton.yesnocancel:                     buttonspanel.children.add(this.createyesbutton(defaultresult));                     buttonspanel.children.add(this.createnobutton(defaultresult));                     buttonspanel.children.add(this.createcancelbutton(defaultresult));                     break;                 case messageboxbutton.yesno:                     buttonspanel.children.add(this.createyesbutton(defaultresult));                     buttonspanel.children.add(this.createnobutton(defaultresult));                     break;                 default:                     throw new argumentoutofrangeexception("button");             }         }           private button createokbutton(messageboxresult defaultresult)         {             var okbutton = new button             {                 name = "okbutton",                 content = "ok",                 isdefault = defaultresult == messageboxresult.ok,                 tag = messageboxresult.ok,             };              okbutton.click += this.buttonclick;              return okbutton;         }           private button createcancelbutton(messageboxresult defaultresult)         {             var cancelbutton = new button             {                 name = "cancelbutton",                 content = "cancel",                 isdefault = defaultresult == messageboxresult.cancel,                 iscancel = true,                 tag = messageboxresult.cancel,             };              cancelbutton.click += this.buttonclick;              return cancelbutton;         }           private button createyesbutton(messageboxresult defaultresult)         {             var yesbutton = new button             {                 name = "yesbutton",                 content = "yes",                 isdefault = defaultresult == messageboxresult.yes,                 tag = messageboxresult.yes,             };              yesbutton.click += this.buttonclick;              return yesbutton;         }           private button createnobutton(messageboxresult defaultresult)         {             var nobutton = new button             {                 name = "nobutton",                 content = "no",                 isdefault = defaultresult == messageboxresult.no,                 tag = messageboxresult.no,             };              nobutton.click += this.buttonclick;              return nobutton;         }           private void buttonclick(object sender, routedeventargs e)         {             messageboxresult = (messageboxresult)(sender button).tag;              close();         }          private void applyoptions(messageboxoptions options)         {             if ((options & messageboxoptions.rightalign) == messageboxoptions.rightalign)             {                 messagetext.textalignment = textalignment.right;             }              if ((options & messageboxoptions.rtlreading) == messageboxoptions.rtlreading)             {                 flowdirection = flowdirection.righttoleft;             }         }          /// <summary>         /// create image system's icons         /// </summary>         /// <param name="icon">messagebox icon</param>         private void createimage(messageboximage icon)         {             switch (icon)             {                 case messageboximage.none:                     imageplaceholder.visibility = visibility.collapsed;                     break;                 case messageboximage.information:                     imageplaceholder.source = systemicons.information.toimagesource();                     break;                 case messageboximage.question:                     imageplaceholder.source = systemicons.question.toimagesource();                     break;                 case messageboximage.warning:                     imageplaceholder.source = systemicons.warning.toimagesource();                     break;                 case messageboximage.error:                     imageplaceholder.source = systemicons.error.toimagesource();                     break;                 default:                     throw new argumentoutofrangeexception("icon");             }         }          /// <summary>         /// show startup animation         /// </summary>         /// <param name="sender">sender parameter</param>         /// <param name="e">argument parameter</param>         private void window_loaded(object sender, routedeventargs e)         {             // set here height after width has been set              // details expander won't stretch message box when it's opened             sizetocontent = sizetocontent.height;              var animation = tryfindresource("loadanimation") storyboard;              animation.begin(this);         }          /// <summary>         /// show closing animation         /// </summary>         /// <param name="sender">sender parameter</param>         /// <param name="e">argument parameter</param>         private void messageboxwindow_closing(object sender, canceleventargs e)         {             if (!this._animationran)             {                 // animation won't run if window allowed close,                  // here animation starts, , window's closing canceled                 e.cancel = true;                  var animation = tryfindresource("unloadanimation") storyboard;                  animation.completed += this.animationcompleted;                  animation.begin(this);             }         }          /// <summary>         /// signals closing animation ran, , close window (for real time)         /// </summary>         /// <param name="sender">sender parameter</param>         /// <param name="e">argument parameter</param>         private void animationcompleted(object sender, eventargs e)         {             this._animationran = true;              close();         }          #endregion     } 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -