[英]How to show a Customized MessageBox?
我想在Windows 8手机应用程序中显示类似MessageBox的内容,但是不幸的是,我找不到解决方法。
Test.Show("Desc", "Title");
和我在DLL中的方法
public static class Test
{
public static void Show(object buttonsContent, object title)
{
}
}
如何在APP的类库中显示我的Customized MessageBox
。
因为在此示例中,您已将两个String对象传递给Show(object, object)
方法,所以可以只使用MessageBox.Show(String, String, MessageBoxButton)
来显示对话框。
但是,如果要在MessageBox中显示文本以外的内容,则必须自己实现对话框视图。 使用PopUp
类( http://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.xaml.controls.primitives.popup ),可以轻松完成此操作。 它将在existingin视图的顶部自定义内容,您可以将内容以及对话框按钮放入其中,然后可以对其进行处理。
您可以轻松地重新设置Windows Phone Toolkit的CustomMessageBox
控件的样式。 您需要在Blend中打开.xaml文件,并编辑CustomMessageBox
样式的CustomMessageBox
,以便可以在自己的项目中使用它。 您可以在此样式的ControlTemplate
中添加自己的内容。 然后,您将该样式复制到可以访问它的位置,在下面的示例中,我将其放入App.xaml
文件中。 您可以这样声明CustomMessageBox
:
new CustomMessageBox
{
Caption = "A messagebox",
Style = App.Current.Resources["YourEditedStyleKey"] as Style,
}.Show();
您可以在CustomMessageBox上设置的各种属性上控制TemplateBinding。 例如,您可以设置自定义字体
FontFamily = App.Current.Resources["MuseoSans500"] as FontFamily,
并以您的自定义样式使用模板绑定来使用此字体:
FontFamily="{TemplateBinding FontFamily}"
您可以使用ChildWindow类提供一个可以在父窗口上显示的窗口。
你可以在这里查看示例
您可以像这样在XAML设计页面上创建一个弹出控件
<Popup x:Name="_Popup">
<Border Margin="30,190,24,194" CornerRadius="17" BorderThickness="3" BorderBrush="Gray" Background="White" Opacity="0.9">
<Grid x:Name="MsgPanel" Grid.Row="1" VerticalAlignment="Center" Height="250">
<TextBlock Name="txtTitle" Text="Message" Foreground="Black" FontSize="28" HorizontalAlignment="Center" FontFamily="Calibri" Height="39" VerticalAlignment="Top" />
<Border Margin="6,70,6,105" BorderBrush="Black" CornerRadius="17" BorderThickness="3">
<TextBox Name="txtmsgMobNo" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="Black" MaxLength="10" FontSize="25" FontFamily="Courier New" FontWeight="Bold">
</TextBox>
</Border>
<Border Margin="58,150,222,40" CornerRadius="10" BorderThickness="3" Background="Silver" BorderBrush="Gray">
<Button Name="btnMsgSend" Content="Send" BorderBrush="{x:Null}" Background="{x:Null}" Foreground="Black" Height="68" Width="144" Click="btnMsgSend_Click" Margin="0,-10,0,0"></Button>
</Border>
</Grid>
</Border>
</Popup>
在您想打开弹出窗口的任何地方的代码中,都输入_Popup.Isopen = true;。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.