c# - How to show dialog box without needing a metro accent theme? -


i want show metro-style dialog box so:

public async void button_click(object sender, routedeventargs e) {    var metrowindow = (application.current.mainwindow metrowindow);    await metrowindow.showmessageasync("title", "body"); } 

enter image description here

however, kept throwing error:

an unhandled exception of type 'system.nullreferenceexception' occurred in mscorlib.dll

with stack trace:

at mahapps.metro.controls.dialogs.basemetrodialog.handletheme()

at mahapps.metro.controls.dialogs.basemetrodialog.initialize()

at mahapps.metro.controls.dialogs.basemetrodialog..ctor(metrowindow owningwindow, metrodialogsettings settings)

...

at system.threading.threadhelper.threadstart()

so after lot of fiddling, realized needed include accent in app.xaml resources give color scheme.

<resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/accents/cobalt.xaml" />  

however, i've built program without , including has messed styling. furthermore, there aren't many accents total see here , can't find 1 fits scheme.

i've been trying give showmessageasync method it's own color scheme directly commands such as

metrowindow.metrodialogoptions.colorscheme = metrodialogoptions.colorscheme  // metrodialogcolorscheme.theme  // metrodialogcolorscheme.accented  // metrodialogcolorscheme.inverted; 

but same error continues appear. there way around this? how dialog box use own style?

edit

i've downloaded file here: https://github.com/mahapps/mahapps.metro/blob/master/mahapps.metro/styles/accents/cobalt.xaml

and in resourcedirectory.mergeddictionaries replaced

  <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/accents/cobalt.xaml" /> 

with

  <resourcedictionary source="cobalt.xaml" /> 

and that's enough break function. can see that theme still in effect, when try trigger dialog box, window fade dialog box doesn't appear , need restart program. what's going on?

you should @ thememanager. set appstyle when application start :

thememanager.changeappstyle(this, thememanager.accents.first(x => x.name == "red"), thememanager.detectappstyle().item1); 

here example of theme avaible :

enter image description here

to use own style can add accents :

thememanager.addaccent("xpertdocblue", new uri("xpertdocblue.xaml", urikind.relative)); 

try add resourcedictionary

here mine:

<controls:metrowindow.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/controls.xaml"/>             <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/fonts.xaml"/>             <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/colors.xaml"/>             <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/accents/baselight.xaml"/>             <resourcedictionary source="pack://application:,,,/xpertdoc.portalwordaddin.views;component/resources/icons.xaml"/>             <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/accents/baselight.xaml" />             <resourcedictionary source="xpertdocblue.xaml" />         </resourcedictionary.mergeddictionaries>     </resourcedictionary> </controls:metrowindow.resources> 

and here custom accent (xpertdocblue.xaml):

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     <color x:key="highlightcolor">#ff2b579a</color>      <color x:key="accentcolor">#ff2b579a</color>     <!--60%-->     <color x:key="accentcolor2">#cc2b579a</color>     <!--40%-->     <color x:key="accentcolor3">#992b579a</color>     <!--20%-->     <color x:key="accentcolor4">#662b579a</color>      <!-- re-set brushes -->     <solidcolorbrush x:key="highlightbrush" color="{staticresource highlightcolor}" />     <solidcolorbrush x:key="accentcolorbrush" color="{staticresource accentcolor}"/>     <solidcolorbrush x:key="accentcolorbrush2" color="{staticresource accentcolor2}"/>     <solidcolorbrush x:key="accentcolorbrush3" color="{staticresource accentcolor3}"/>     <solidcolorbrush x:key="accentcolorbrush4" color="{staticresource accentcolor4}"/>      <solidcolorbrush x:key="windowtitlecolorbrush" color="{staticresource accentcolor}" />      <solidcolorbrush x:key="accentselectedcolorbrush" color="white" />      <lineargradientbrush x:key="progressbrush" endpoint="0.001,0.5" startpoint="1.002,0.5">         <gradientstop color="{staticresource highlightcolor}" offset="0" />         <gradientstop color="{staticresource accentcolor3}" offset="1" />     </lineargradientbrush>      <solidcolorbrush x:key="checkmarkfill" color="{staticresource accentcolor}" />     <solidcolorbrush x:key="rightarrowfill" color="{staticresource accentcolor}" />      <color x:key="idealforegroundcolor">white</color>     <solidcolorbrush x:key="idealforegroundcolorbrush" color="{staticresource idealforegroundcolor}"/>  </resourcedictionary> 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -