I created a style for the MessageBox of the Extended Toolkit. It works fine as long as I use it in a WPF project with an app.xaml where I can set the resource in the Application.Resources. When I want to use it in a WPF User Control library there is no app.xaml. Is there any way to use the style there? I can't use the Window.Resources, because the MessageBox is a new window itself.
I've found a solution.
First I've created a static Style property that returns the style I've defined in the ResourceDictionary.
public static System.Windows.Style MyMessageBoxStyle
{
get
{
var myResourceDictionary = new ResourceDictionary
{
Source = new Uri("/myApplication;component/Style/MyMessageBoxStyle.xaml", UriKind.RelativeOrAbsolute)
};
System.Windows.Style defaultMessageBoxStyle = (System.Windows.Style)myResourceDictionary["DefaultMessageBoxStyle"];
return defaultMessageBoxStyle;
}
}
Then I can apply that Style when calling the MessageBox
MessageBoxResult result = MessageBox.Show("text", "title", MessageBoxButton.YesNoCancel, MyMessageBoxStyle );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.