简体   繁体   中英

Display gridcontrol in DXMessageBox

I have a wpf application in which on clicking a button "Submit" a DXMessage Box appears with a summary text outlining the various operations made by the user. The text to be displayed was too large and the default textbox width and height of the DXMessageBox was not sufficient to display the text in a readable format to the user. In order to overcome this I wrote my own control template for the DXMessageBox in my app.xaml file:

<Application.Resources>
    <ResourceDictionary>
        <ControlTemplate TargetType="{x:Type dx:DXMessageBox}" x:Key="DXMessageBoxTemplate">
            <TextBox Height=500 Width=500 Text="{Binding Path=Text, RelativeSource={RelativeSource TemplatedParent}}"/>
        </ControlTemplate>
        <Style TargetType="{x:Type dx:DXMessageBox}">
            <Setter Property="Template" Value="{StaticResource DXMessageBoxTemplate}"/>
         </Style>
    </ResourceDictionary>
</Application.Resources>

Now this works fine and the text is automatically bound to the variable in my view model class as follows:

string result;
DXMessageBox.Show(result);

The variable "result" is data that I am deriving from a datatable in myview model class and converting to string.

However my application requires the entire gridcontrol to be displayed in the DXMessageBox, so I tried the above same approach but I get stuck at two places:
1)In the controlTemplate defined in the app.xaml file where I shall add my gridcontrol , what should the itemsSource of the xaml be such that my gridcontrol is bound to the datatable declared in my viewmodel class.
2)When I call the DXMessageBox.Show method after adding the grid control, what arguments to pass to that method.

It is better to use the DXDialog instead of DXMessageBox to accomplish your task, because the DXMessageBox is not intended to be used for displaying custom content like DXGrid.

When working with the DXDialog, just create a separate UserControl that contains your DXGrid and implements all related presentation logic and pass this UserControl into DXDialog.Content property:

void ShowDialog_Click_1(object sender, RoutedEventArgs e) {
    DXDialog dlg = new DXDialog("Information", DialogButtons.Ok, true);
    dlg.Content = new UserControlWithDXGrid();
    dlg.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
    dlg.Owner = this;
    dlg.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
    dlg.ShowDialog();
}

PS I see you are tagged this question with MVVM tag. Thus I believe in this case you should use the DialogService to accomplish this task in MVVM-way. Please start from reading documentation that clearly describe all needed steps in this regard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM