[UWP] [ContentDialog]在UWP类(Dll文件)中使用ContentDialog? [英] [UWP][ContentDialog] Using ContentDialog in UWP class (Dll file)?
问题描述
如何从dll文件中显示contentdialog?我需要显示带有错误图标的错误消息。
How do I get a contentdialog to display in from a dll file? I have a need to display a error message with the error icon.
这是调用函数来显示消息框的代码:
Here's the code that calls a function to display a messagebox:
' Dim a As Task(Of Boolean) = DisplayMessageBox(errormsg)
' a.Wait()
这是实际的功能代码:
Here's the actual function code:
Private Async Function DisplayMessageBox(errormsg As String) As Task(Of Boolean)
If errormsg <> "" Then
Dim title = New TextBlock()
title.Inlines.Add(New Documents.Run() With
{
.Text = ChrW(&HE783).ToString(),
.FontFamily = New FontFamily("Segoe MDL2 Assets")
})
title.Inlines.Add(New Documents.Run() With
{
.Text = errormsg
})
Dim dialog = New ContentDialog() With
{
.Title = title,
.PrimaryButtonText = "OK",
.HorizontalAlignment = HorizontalAlignment.Center,
.VerticalAlignment = VerticalAlignment.Center
}
Dim a As IAsyncOperation(Of ContentDialogResult) = dialog.ShowAsync
a.AsTask.Wait()
Return True
Else
Return False
End If
End Function
一旦你消除了不可能的事,无论剩下什么,没有很抱歉不可能,必须是真相。 - 夏洛克·福尔摩斯。轻声说话并带上一根大棒 - 西奥多罗斯福。恐惧导致愤怒,愤怒导致仇恨,仇恨导致痛苦 - 尤达。博客 -
http://www.computerprofessions.us
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - Sherlock Holmes. speak softly and carry a big stick - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.us
推荐答案
你好思想家,
要制作一般的contentdialog节目,我修改了你的一些代码,结果如下:
To make a general contentdialog shows I modified some of your code and here is the result:
调用代码:
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim TestClass As New ClassLibrary1.Class1
Await TestClass.DisplayMessageBox("test")
End Sub
类库中的代码:
Public Async Function DisplayMessageBox(errormsg As String) As Task(Of Boolean)
If errormsg <> "" Then
Dim title = New TextBlock()
title.Inlines.Add(New Documents.Run() With
{
.Text = ChrW(&HE783).ToString(),
.FontFamily = New FontFamily("Segoe MDL2 Assets")
})
title.Inlines.Add(New Documents.Run() With
{
.Text = errormsg
})
Dim dialog = New ContentDialog() With
{
.Title = title,
.PrimaryButtonText = "OK",
.HorizontalAlignment = HorizontalAlignment.Center,
.VerticalAlignment = VerticalAlignment.Center
}
Dim a As ContentDialogResult = Await dialog.ShowAsync()
Return True
Else
Return False
End If
End Function
我修改了有关异步和等待部分的代码。在使用a.AsTask.Wait()的代码中,它实际上是一个同步过程。有关Task.Wait
https://msdn.microsoft.com/en-us/library/dd235606(v=vs.110).aspx?cs-save-lang= 1& cs-lang = vb#code-snippet-2 这就产生了问题。我怀疑这个帖子在这里被阻止。
I've modified the code about the async and await part. In your code when your use a.AsTask.Wait() it is actually a sync process. See here for details about Task.Wait https://msdn.microsoft.com/en-us/library/dd235606(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 This makes the problem. I suspect the thread is blocked here.
祝你好运,
Barry
这篇关于[UWP] [ContentDialog]在UWP类(Dll文件)中使用ContentDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!