This is a migrated thread and some comments may be shown as answers.

[Solved] Cancel Open File Dialog in SpreadSheet Programatically

4 Answers 152 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sai
Top achievements
Rank 1
sai asked on 25 Mar 2015, 02:03 PM
Hi,
Based on some condition in code behind(.cs file) I want to prevent or not prevent spreadsheet to open the file dialog.
I'm using the following code in XAML
<controls:GodRadRibbonBackstageItem Header="Open"
                                            CloseOnClick="True"
                                            Icon="{telerik:IconResource IconRelativePath=16/open.png, IconSources={StaticResource IconPaths}}"
                                            Command="{Binding Path=OpenFile.Command}"
                                            IsEnabled="{Binding Path=OpenFile.IsEnabled}"
                                            IsSelectable="False" />

Thanks,
sai

4 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 30 Mar 2015, 10:23 AM
Hello Sai,

The DataContext property of the RadRibbonView is set to the RadSpreadsheet's command descriptors.  In the snippet below is demonstrated how to set the IsEnabled property of the OpenFile command:
this.radSpreadsheet.CommandDescriptors.OpenFile.IsEnabled = false;

However, I am not sure if I fully understand your scenario and if this suggestion does not fit your needs, please, let me know.

Regards,
Tanya
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
sai
Top achievements
Rank 1
answered on 30 Mar 2015, 12:34 PM
I'm not looking for this. But I implemented this. (The below code is working fine for me), Suggest me if I can make it better than this.
I removed this Command "Command="{Binding Path=OpenFile.Command}"" from XAML
And implemented click event for this in code behind
 var radRibbonBackstageItem = ribbonView.Backstage.Items.Cast<RadRibbonBackstageItem>().First(x => x.Header.ToString() == "Open");
            radRibbonBackstageItem.Click += radRibbonBackstageItem_Click;
 void radRibbonBackstageItem_Click(object sender, RoutedEventArgs e)
        {
            if(A)
                OpenFileDialog();
        }


  private void OpenFileDialog()
        {
            var openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == true)
            {
                try
                {
                    var extension = Path.GetExtension(openFileDialog.File.Name);
                    using (Stream input = openFileDialog.File.OpenRead())
                    {
                        radSpreadsheet.Workbook = WorkbookFormatProvidersManager.Import(extension, input);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
0
Tanya
Telerik team
answered on 30 Mar 2015, 05:20 PM
Hello Sai,

The approach is appropriate and there is not much else to suggest. The only thing I noticed is the code for getting the RadRibbonBackstageItem in the code behind. You could set the Name property of the RadRibbonBackstageItem instead of checking its name:
<telerik:RadRibbonBackstageItem Header="Open" Name="ribbonBackstageItemOpenFile"

After doing this you can reach the item just by typing its name from the XAML:
this.ribbonBackstageItemOpenFile.Click += ribbonBackstageItemOpenFile_Click;

Hope this helps.

Regards,
Tanya
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
sai
Top achievements
Rank 1
answered on 01 Apr 2015, 12:49 PM
That's great! Thanks a lot...
Tags
Spreadsheet
Asked by
sai
Top achievements
Rank 1
Answers by
Tanya
Telerik team
sai
Top achievements
Rank 1
Share this question
or