This project has moved and is read-only. For the latest updates, please go here.

Using DataTemplate in TaskDialog.ExpansionDataContent

Sep 28, 2007 at 6:05 AM
Edited Sep 28, 2007 at 6:10 AM
I finally figured out the answer to my previous post ...

Create a simple object:
public class ErrorInfo {

private string formattedText;
public string FormattedText {
get { return formattedText; }
set {
formattedText = value;

Create a Data Template
<DataTemplate x:Key="MyDataTemplate">
<Border BorderThickness="5" CornerRadius="5" BorderBrush="Green" Margin="5">
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Visible" Height="200" ScrollViewer.HorizontalScrollBarVisibility="Visible" Content="{Binding Path=FormattedText}"></ScrollViewer>

Create the dialog in C# and show it
TaskDialog dialog = new TaskDialog();
dialog.Name = "ErrorDialog";
dialog.Title = "Title";
dialog.Header = "An unhandled exception has occurred, please contact support";
dialog.Owner = this;
dialog.StandardButtons = TaskDialogButtons.OK | TaskDialogButtons.Cancel;
dialog.MainIcon = TaskDialogIconConverter.ConvertFrom(TaskDialogIcon.Error);

dialog.ExpansionPosition = TaskDialogExpansionPosition.Header;
dialog.Width = 600;

DataTemplate template = dialog.FindResource("MyDataTemplate") as DataTemplate; // fetch data template from resource file
ErrorInfo info = new ErrorInfo();
info.FormattedText = formatter.Writer.ToString();
dialog.ExpansionContent = info; // set the object to be the data source
dialog.ExpansionContentTemplate = template; // set the data template


TaskDialogResult result = dialog.Result;
if (result.StandardButton == TaskDialogButtons.Cancel)