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

Code behind decorator

8 Answers 183 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Carl
Top achievements
Rank 1
Carl asked on 05 Feb 2016, 09:35 AM
I am trying to find the right syntax to add a drop shadow via code behind.

8 Answers, 1 is accepted

Sort by
0
Masha
Telerik team
answered on 05 Feb 2016, 02:11 PM
Hi Carl,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Carl
Top achievements
Rank 1
answered on 10 Feb 2016, 09:36 AM

I think it would be easier if I posted my code 

 XAML

 

<UserControl
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             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.

0
Carl
Top achievements
Rank 1
answered on 10 Feb 2016, 09:40 AM
I am unsure if this is a second post but the scrollbars on the grid while showing do not actually work.  They display but no scroll behaviour is exhibited.
0
Masha
Telerik team
answered on 10 Feb 2016, 12:24 PM
Hello Carl,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Carl
Top achievements
Rank 1
answered on 10 Feb 2016, 03:20 PM

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 

  1. load the data into a RadGridView.
  2. 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

 

 

0
Masha
Telerik team
answered on 11 Feb 2016, 07:49 AM
Hello 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Carl
Top achievements
Rank 1
answered on 11 Feb 2016, 09:24 AM

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? 

0
Accepted
Masha
Telerik team
answered on 11 Feb 2016, 09:53 AM
Hi Carl,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ContextMenu
Asked by
Carl
Top achievements
Rank 1
Answers by
Masha
Telerik team
Carl
Top achievements
Rank 1
Share this question
or