[Unity] simplest way to have a messagebox
Posted: 28 Dec 2015, 13:51
i want to know what is the simplest way to get a popup messagebox with OK / Cancel buttons
Thanks in advance
Thanks in advance
Welcome to our official discussion site. You’ll find topics on features, bugs, development, and general support here
https://www.noesisengine.com/forums/
<UserControl
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
x:Class="MessageBoxControl">
<Grid Background="#40000000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="25*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25*"/>
<RowDefinition Height="50*"/>
<RowDefinition Height="25*"/>
</Grid.RowDefinitions>
<Border x:Name="dialog" Grid.Column="1" Grid.Column="1" ...>
... message dialog here
</Border>
</Grid>
</UserControl> <Grid
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">
<Grid x:Name="LayoutRoot">
... normal controls placed here
</Grid>
<Grid x:Name="MessageBoxContainer">
... message boxes added here
</Grid>
</Grid> <UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MessageBox">
<Grid x:Name="LayoutRoot" Background="#80000000">
<Border BorderBrush="Black" BorderThickness="1"
HorizontalAlignment="Center" VerticalAlignment="Center" Margin="200,100">
<StackPanel>
<Border Background="Gray" Padding="5,2">
<TextBlock Text="{Binding Title}" FontWeight="Bold" FontSize="14" />
</Border>
<Border Padding="5">
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="14" />
</Border>
<StackPanel x:Name="ButtonsPanel" Orientation="Horizontal" HorizontalAlignment="Center" Margin="5">
<Button Content="{Binding OkText}" Command="{Binding OkCommand}" />
<Button Content="{Binding CancelText}" Command="{Binding CancelCommand}"/>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</UserControl>using System;
using Noesis.UserControls;
using Noesis;
[UserControlSource("Assets/UI/MessageBox.xaml")]
public class MessageBox : UserControl
{
public static DependencyProperty TitleProperty = DependencyProperty.Register(
"Title", typeof(string), typeof(MessageBox), new PropertyMetadata(""));
public string Title
{
get { return GetValue(TitleProperty).ToString(); }
set { SetValue(TitleProperty, value); }
}
public static DependencyProperty MessageProperty = DependencyProperty.Register(
"Message", typeof(string), typeof(MessageBox), new PropertyMetadata(""));
public string Message
{
get { return GetValue(MessageProperty).ToString(); }
set { SetValue(MessageProperty, value); }
}
public static DependencyProperty OkTextProperty = DependencyProperty.Register(
"OkText", typeof(string), typeof(MessageBox), new PropertyMetadata(""));
public string OkText
{
get { return GetValue(OkTextProperty).ToString(); }
set { SetValue(OkTextProperty, value); }
}
public static DependencyProperty CancelTextProperty = DependencyProperty.Register(
"CancelText", typeof(string), typeof(MessageBox), new PropertyMetadata(""));
public string CancelText
{
get { return GetValue(CancelTextProperty).ToString(); }
set { SetValue(CancelTextProperty, value); }
}
public void OnPostInit()
{
Grid root = (Grid)FindName("LayoutRoot");
root.DataContext = this;
}
}
var gui = GetComponent<NoesisGUIPanel>();
Grid root = (Grid)gui.GetContent();
mainWindowRoot = (Grid)root.FindName("xpGrid");
MessageBox msgBox = new MessageBox
{
Title = "Quit?",
Message = "Do you really want to quit?",
OkText = "Yes!",
CancelText = "Cancel",
};
mainWindowRoot.Children.Add(msgBox);
<Grid x:Name="LayoutRoot" Background="#80000000">
mainWindowRoot = (Grid)root.FindName("xpGrid");
mainWindowRoot = (Grid)root.FindName("LayoutRoot");
i have 2 Grids the xpGrid is one under a viewbox and i'm loading the LayoutRoot in another variableThe problem is that the name given in the XAML and the one used in FindName does not match.Code: Select all<Grid x:Name="LayoutRoot" Background="#80000000">It should beCode: Select allmainWindowRoot = (Grid)root.FindName("xpGrid");Code: Select allmainWindowRoot = (Grid)root.FindName("LayoutRoot");