在XAML中定义Windows Phone Toolkit中的CustomMessageBox



我可以在XAML中定义CustomMessageBox吗?我有代码:

<phone:phone:PhoneApplicationPage.Resources>
        <toolkit:CustomMessageBox x:Key="CustomMessageBox" Title="Blabla" IsLeftButtonEnabled="True" LeftButtonContent="OK" Content="blabla" />
</phone:PhoneApplicationPage.Resources>

当我试图运行它时:

(this.Resources["CustomMessageBox"] as CustomMessageBox).Show();

我得到InvalidOperationException - "元素已经是另一个元素的子元素".

是否有可能这样做,或者我必须从代码后面定义它?有什么变通办法吗?

由于这本书(不是广告,只是显示来源),你可以这样做:

1新建UserControl,命名为CustomUserControl.xaml

2为UC添加自定义UI元素

<StackPanel x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}" Margin="0,0,0,10">
 <TextBlock Text="Custom content inside the UserControl XAML" TextWrapping="Wrap"
 HorizontalAlignment="Left"/>
 <MediaElement Source="http://mschannel9.vo.msecnd.net/o9/mix/09/wmv/key01.wmv"/>
 </StackPanel>

3从你的主页运行

var messageBox = new CustomMessageBox
{
Content = new CustomUserControl(),
LeftButtonContent = "OK",
RightButtonContent = "Cancel",
};
messageBox.Show();

似乎现在可以在消息框中播放视频了:)

PS:也发现了一些信息在这里

最新更新