我试图在Windows 8中再次尝试/取消对话框.对话框第一次显示正常,但是再次单击尝试再次失败,我在调用ShowAsync时得到访问被拒绝的异常.我不知道为什么,但奇怪的是,有时代码工作正常,当我放置断点时我没有得到异常.这里真的很无能为力
这是代码.
async void DismissedEventHandler(SplashScreen sender, object e)
{
dismissed = true;
loadFeeds();
}
private async void loadFeeds()
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
try
{
RSSDataSource rssDataSource = (RSSDataSource)App.Current.Resources["RSSDataSource"];
if (rssDataSource != null)
{
await rssDataSource.DownloadFeeds();
await rssDataSource.GetFeedsAsync();
}
AdDataSource ads = (AdDataSource)App.Current.Resources["AdDataSource"];
if (ads != null)
{
await ads.DownloadAds();
}
rootFrame.Navigate(typeof(HomePageView));
Window.Current.Content = rootFrame;
}
catch
{
ShowError();
}
});
}
async void ShowError()
{
// There was likely a problem initializing
MessageDialog msg = new …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用3个命令将MessageDialog添加到Windows Phone 8.1应用程序(WinRT).查看MessageDialog的文档:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.messagedialog.aspx
它说"对话框有一个命令栏,可以支持最多三个命令",所以我认为这不会是一个问题.我拿了他们的例子(在文档中找到)并制作了一个简单的测试应用程序,它在桌面和Windows手机上都运行得很好.然后,我采用相同的示例并向其添加了一个命令:
var messageDialog = new MessageDialog("No internet connection has been found.");
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
messageDialog.Commands.Add(new UICommand(
"Try again",
new UICommandInvokedHandler(this.CommandInvokedHandler)));
messageDialog.Commands.Add(new UICommand(
"Something else",
new UICommandInvokedHandler(this.CommandInvokedHandler)));
messageDialog.Commands.Add(new UICommand(
"Close",
new UICommandInvokedHandler(this.CommandInvokedHandler)));
// Set the command that will be invoked by default
messageDialog.DefaultCommandIndex = 0;
// Set the command to be invoked when escape is pressed
messageDialog.CancelCommandIndex = 1;
// Show …Run Code Online (Sandbox Code Playgroud) 我想编写自己的控件,当调用ctor时,会显示一个MessageBox.
public class Class1
{
public Class1()
{
ShowDialog();
}
void ShowDialog()
{
SynchronizationContext context = SynchronizationContext.Current;
if (context != null)
{
context.Post((f) =>
{
MessageDialog dialog = new MessageDialog("Hello!");
dialog.ShowAsync();
}, null);
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我的类被某人使用,并编写如下代码,则始终会抛出UnauthorizedAccessException dialog.ShowAsync();
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ClassLibrary1.Class1 c1 = new ClassLibrary1.Class1();
MessageDialog dialog1 = new MessageDialog("");
dialog1.ShowAsync();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法毫无例外地显示消息对话框?
我找到了一种方式,享受它!
Task ShowDialog()
{
CoreDispatcher dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
Func<object, Task<bool>> action = null;
action = async (o) =>
{
try
{
if (dispatcher.HasThreadAccess) …Run Code Online (Sandbox Code Playgroud) .net c# unauthorizedaccessexcepti messagedialog windows-runtime
我试图在我的WinRT应用程序中关闭MessageDialog.我注意到如果我试图一次显示两个消息对话框,我得到一个UnauthorizedAccessException.为了避免这种情况,我想关闭现有的消息对话框,如果它是打开的.我用它来显示对话框:
MessageDialog md = new MessageDialog(" ");
private void MessageBox(string s)
{
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
md.Content = s;
//CLOSE HERE
md.ShowAsync();
}
);
}
Run Code Online (Sandbox Code Playgroud)
我怎么关闭它?
我目前正在尝试将Facebook SDK添加到我的应用程序的iOS版本中.登录,注销,共享和请求功能目前都在工作,但我很难让MessageDialog功能正常工作.Facebook应用程序和Facebook Messenger应用程序目前已安装在我的设备上.但是,每当我调用'FBDialog canPresentMessageDialogWithParams:params'时,它返回false.
我的猜测是,当应用程序仍处于开发模式时,此功能不起作用,但这只是猜测.有没有人知道Message Dialog是否适用于正在开发的应用程序?或者你对我做错了什么有任何想法?
我还包括了我的代码,以防我犯了任何骨头错误.任何帮助是极大的赞赏!
// Check if the Facebook app is installed and we can present the share dialog
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:@"https://www.facebook.com/"];
params.name = @"Flash Bear";
params.caption = nil;
params.picture = nil;
params.linkDescription = @"I'm playing Flash Bear. Why don't you come join me?";
// If the Facebook Messenger app is installed and we can present the share dialog
if ([FBDialogs canPresentMessageDialogWithParams:params]) {
// Present message dialog
[FBDialogs presentMessageDialogWithParams:params
clientState:nil …Run Code Online (Sandbox Code Playgroud) Delete单击后,这就是我的功能。谁能告诉我如何执行简单的确认功能?
ASP.net C#。
以前我有这个
ScriptManager.RegisterStartupScript(this,
this.GetType(),
"script",
"confirm('Are you sure you want to Delete Your Discussion?');",
true);
Run Code Online (Sandbox Code Playgroud)
但以上代码在删除后运行。
protected void lnk_delete_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string fieldID = grdrow.Cells[0].Text;
string query = "Delete from Comment where DiscussionID=@id";
SqlCommand cmd = new SqlCommand(query, cn);
cmd.Parameters.AddWithValue("@id", fieldID);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
string query1 = "Delete from Discussion where DIscussionID=@id";
SqlCommand cmd1 = new SqlCommand(query1, cn);
cmd1.Parameters.AddWithValue("@id", fieldID);
cn.Open();
cmd1.ExecuteNonQuery();
cn.Close();
GridView1.DataBind();
}
Run Code Online (Sandbox Code Playgroud) 我想知道如何将图像添加到MessageDialog框.我尝试了下面的代码,图像无处可寻
else if(button == B){
String text = "blahblahblahblahblah";
JTextArea textArea = new JTextArea(text);
textArea.setColumns(30);
textArea.setLineWrap( true );
textArea.setWrapStyleWord( true );
textArea.setSize(textArea.getPreferredSize().width, 1);
Font font = new Font("Verdana", Font.BOLD, 12);
textArea.setFont(font);
textArea.setForeground(Color.BLUE);
JOptionPane.showMessageDialog(
null, textArea, "Border States", JOptionPane.PLAIN_MESSAGE);
image2 = new ImageIcon(getClass().getResource("borderstates.jpg"));
label2 = new JLabel(image2);
add(label2);
Run Code Online (Sandbox Code Playgroud) 我想以下面的方式创建一个消息对话框
例如:我的组合框有2个名称," chkbx "(复选框的符号名称)," txtedt "(文本字段的符号名称).
每当我从组合框下拉列表中选择chkbox或txtedt时,我的组合框应该分别将我连接到实际的checkbox和textedit元素.
状态栏上有一个" 显示对话框"按钮,当我按下该按钮时,它应该弹出选中的选项(复选框或行编辑)
请建议我怎么做.
编辑这里是代码和我面对的组合框选项的问题是,我既不能在我的消息对话框中获取图标也不知道我怎么能在消息对话框中看到复选框或行编辑,我是一个初学者和挣扎探索QML中使用的棘手方法..
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.1
import QtQuick.Window 2.0
Item {
id: root
width: 580
height: 400
SystemPalette { id: palette }
clip: true
//! [messagedialog]
MessageDialog {
id: messageDialog
visible: messageDialogVisible.checked
modality: messageDialogModal.checked ? Qt.WindowModal : Qt.NonModal
title: windowTitleField.text
text: customizeText.checked ? textField.text : ""
informativeText: customizeInformativeText.checked ? informativeTextField.text : ""
onButtonClicked: console.log("clicked button " + clickedButton)
onAccepted: lastChosen.text …Run Code Online (Sandbox Code Playgroud) 我有一个ViewModel,它在同步方法中实例化一个事件.该事件向UI发出信号,表示在继续之前我们需要来自用户的"是"或"否"回答.
我试图显示MessageDialog并等待用户提供答案 - 是或否.我很难做到这一点.我目前正UnauthorizedAccessException试图这样做.
以下是UI中的代码:
async Task<bool> Instance_SwitchConfirmation(string question)
{
MessageDialog md = new MessageDialog(question);
md.Commands.Add(new UICommand("Yes", CommandInvokedHandler));
md.Commands.Add(new UICommand("No", CommandInvokedHandler));
md.ShowAsync();
return this.canSwitch;
}
async void CommandInvokedHandler(IUICommand command)
{
this.canSwitch = command.Label == "Yes" ? true : false;
}
Run Code Online (Sandbox Code Playgroud)
我试过了:
var uiContext = TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(() => {
MessageDialog md = new MessageDialog(question);
md.Commands.Add(new UICommand("Yes", CommandInvokedHandler));
md.Commands.Add(new UICommand("No", CommandInvokedHandler));
md.ShowAsync();
},
new System.Threading.CancellationToken(),
TaskCreationOptions.PreferFairness, uiContext);
Run Code Online (Sandbox Code Playgroud)
但这失败了同样的例外.
最后,如果我只是等待MessageDialog,则不显示对话框并且UI线程锁定.
MessageDialog md = new MessageDialog(question);
md.Commands.Add(new UICommand("Yes", CommandInvokedHandler));
md.Commands.Add(new …Run Code Online (Sandbox Code Playgroud) private IAsyncOperation<ContentDialogResult> _Task = null;
private ContentDialog _message = null;
_message = new ContentDialog()
{
Content = "Hello",
PrimaryButtonText = "EXIT",
IsPrimaryButtonEnabled = true,
};
_message.PrimaryButtonClick += message_PrimaryButtonClick;
_Task = _message.ShowAsync();
Run Code Online (Sandbox Code Playgroud)
在这里,我创建了一个内容对话框的任务,以便我可以从代码中显式关闭ContenDialog.
How can I prevent dialog from closing when Home key is pressed and relaunched
Run Code Online (Sandbox Code Playgroud) messagedialog ×10
c# ×5
windows-8 ×2
.net ×1
asp.net ×1
async-await ×1
combobox ×1
confirmation ×1
facebook ×1
image ×1
ios ×1
java ×1
joptionpane ×1
msgbox ×1
qml ×1
qt-quick ×1
qt5 ×1
swing ×1
windows ×1
winrt-xaml ×1