8 Answers, 1 is accepted
Do you want the shadow to be around the RadContextMenu? Please check the code snippet below which demonstrated this approach:
<TextBox Margin="10" x:Name="textbox"> <telerik:RadContextMenu.ContextMenu> <telerik:RadContextMenu x:Name="customContextMenu"> <telerik:RadMenuItem Header="Copy" /> <telerik:RadMenuItem Header="Paste" /> <telerik:RadMenuItem Header="Cut" /> </telerik:RadContextMenu> </telerik:RadContextMenu.ContextMenu></TextBox>public partial class MainWindow : Window{ DropShadowEffect shadowEffect; public MainWindow() { InitializeComponent(); this.shadowEffect = new DropShadowEffect { Color = new Color { A = 100, R = 220, G = 255, B = 0 }, Direction = 270, BlurRadius = 5, ShadowDepth = 1, Opacity = 1 }; this.customContextMenu.Effect = this.shadowEffect; this.customContextMenu.Margin = new Thickness(5); }}Regards,
Masha
Telerik
I think it would be easier if I posted my code
XAML
<UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="Control.DataViewGrid.View.DataViewGrid" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <telerik:RadGridView Margin="0,0,10,10" x:Name="safeDataGridView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding QueryTable}" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" /> </StackPanel></UserControl>C#
using System;using System.Linq;using System.Windows.Controls;using Control.DataViewGrid.ViewModel;using Telerik.Windows;using Telerik.Windows.Controls;namespace Control.DataViewGrid.View{ /// <summary> /// Interaction logic for DataViewGrid.xaml /// </summary> public partial class DataViewGrid : UserControl { private vmDataGridView dataContext = new vmDataGridView(); //public SQLQuery Query; private string SQL { get; set; } private string ConnectionString { get; set; } //public datatable public void LoadDataViewGrid(bool developermode, string connectionstring, string sql) { developerMode = developermode; SQL = sql; ConnectionString = connectionstring; dataContext = new vmDataGridView(ConnectionString,SQL,string.Empty); ContextMenu(); } public DataViewGrid() { InitializeComponent(); DataContext = dataContext; } private bool developerMode = false; public bool DeveloperMode { set { developerMode = value; ContextMenu(); } } private void ContextMenu() { if (developerMode) { DataContext = dataContext; RadContextMenu radMenuContext = new RadContextMenu(); RadMenuItem properties = new RadMenuItem(); properties.Header = "Properties"; properties.Click += RadMenuItem_Click; radMenuContext.Items.Add(properties); RadContextMenu.SetContextMenu(this.safeDataGridView, radMenuContext); } } private void RadMenuItem_Click(Object sender, RadRoutedEventArgs e) { RadMenuItem item = sender as RadMenuItem; //string x = item.Header.ToString(); var PropertyWindow = new frmProperties(); if (PropertyWindow.ShowDialog() == true) { string MyXML = PropertyWindow.XML; } } private void RadGridView_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e) { } }}The problem I am having is that This.shadowEffect seems to not be exposed.
Could you please provide some more details regarding scroll-bars issue. Do you use implicit styles and what theme do you use? Also, it would be very helpful (for shadow problem) if you can make a small runnable project and send it to us so we can address the issue faster.
Thank you in advance for your cooperation.
Regards,
Masha
Telerik
Hi Marsha
Given that you are talking about two things I have not researched styles and theme perhaps you could take the lead. But to assist I can explain what the code is above. This code has two functions
- load the data into a RadGridView.
- From within the DataGrid I access a RadContextMenu through this function "RadMenuItem_Click"
To save you a little time you could use
using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Data;using System.Linq;using System.Text;namespace Control.DataViewGrid.ViewModel{ public static class Ext_CollectionExtensions { public static ObservableCollection<DataRow> ToObservableCollection(this DataTable coll) { var c = new ObservableCollection<DataRow>(); foreach (DataRow e in coll.Rows) c.Add(e); return c; } }}
this DataTable extension I wrote to populate the DataContext. Just fill a datatable and then use dataTable.ToObservableCollection(); A bit quick and dirty but good for testing.
The whole piece is actually a UserControl I am writing is that something of relevance?
/Carl
I've created a sample demo where is demonstrated how to apply the shadow to the RadContextMenu in code behind. I've used the way from my first post to achieve the approach. Please note when the shadow effect is applied it is necessary Margin property to be set in order the shadow to be visible.
Take a look and let me know how it goes.
Regards,
Masha
Telerik
Hi Marsha
That has resolved the issue of the drop shadow, ultimately it came down to missing references. I believe now that this is largely due to this being a control not a window. Something I could not have easily discovered without your sample.
This is the references I ended up with.
using System;using System.Linq;using System.Windows;using System.Windows.Controls;using System.Windows.Media;using System.Windows.Media.Effects;using Control.DataViewGrid.Data;using Control.DataViewGrid.ViewModel;using Telerik.Windows;using Telerik.Windows.Controls;Could I get some help with the scroll bars too. Or is it more convenient for me to make a new post?
I'm glad you were able to resolve the issue with the shadow.
Since the scroll-bar question is not related to this thread I would ask you to open a new forum in the corresponding section and ask your question there. This way the communication history in the forum will be organized better and you will get better assistance.
Thank you for the understanding.
Regards,
Masha
Telerik