Error in usercontrol constructor "object reference not set to an instance of an object"

1 posts, 0 answers
  1. Chirag
    Chirag avatar
    37 posts
    Member since:
    May 2011

    Posted 14 Feb 2013 Link to this post

    Hi to all 

    i am using telerik silverlight 2012 sp1 controls in my project 

    while using RadImageEditorUI control in page and try to set some property of control in constructor gives error 

    Please Guide me for resolve this problems 

    Code 
    <UserControl x:Class="MyProject.CustomImageEditor"
        xmlns:tools="clr-namespace:Telerik.Windows.Media.Imaging.Tools;assembly=Telerik.Windows.Controls.ImageEditor"
        xmlns:commands="clr-namespace:Telerik.Windows.Media.Imaging.ImageEditorCommands.RoutedCommands;assembly=Telerik.Windows.Controls.ImageEditor"
        mc:Ignorable="d" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
         
        <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Width="Auto">
            <telerik:RadImageEditorUI x:Name="RImgEditor"  Margin="5" Grid.Row="1">
                <telerik:RadImageEditorUI.ImageToolsSections>
                    <telerik:ImageToolsSection Header="Transform">
     
                        <telerik:ImageToolItem ImageKey="Rotate90CW" Text="Rotate 90"  Command="commands:ImageEditorRoutedCommands.Rotate90Clockwise" />
                        <telerik:ImageToolItem ImageKey="Rotate180CW" Text="Rotate 180"  Command="commands:ImageEditorRoutedCommands.Rotate180" />
                        <telerik:ImageToolItem ImageKey="Rotate90CCW" Text="Rotate 270"  Command="commands:ImageEditorRoutedCommands.Rotate90Counterclockwise" />
     
                        <telerik:ImageToolItem ImageKey="FlipHorizontal" Text="Flip Horizontal"  Command="commands:ImageEditorRoutedCommands.FlipHorizontal" />
                        <telerik:ImageToolItem ImageKey="FlipVertical" Text="Flip Vertical"  Command="commands:ImageEditorRoutedCommands.FlipVertical" />
                    </telerik:ImageToolsSection>
     
                    <telerik:ImageToolsSection Header="Adjust" >
                        <telerik:ImageToolItem ImageKey="HueShift" Text="Hue Shift" Command="commands:ImageEditorRoutedCommands.ExecuteTool">
                            <telerik:ImageToolItem.CommandParameter>
                                <tools:HueShiftTool />
                            </telerik:ImageToolItem.CommandParameter>
                        </telerik:ImageToolItem>
                        <telerik:ImageToolItem ImageKey="Saturation" Text="Saturation"  Command="commands:ImageEditorRoutedCommands.ExecuteTool">
                            <telerik:ImageToolItem.CommandParameter>
                                <tools:SaturationTool />
                            </telerik:ImageToolItem.CommandParameter>
                        </telerik:ImageToolItem>
                        <telerik:ImageToolItem ImageKey="Contrast" Text="Contrast"  Command="commands:ImageEditorRoutedCommands.ExecuteTool" >
                            <telerik:ImageToolItem.CommandParameter>
                                <tools:ContrastTool />
                            </telerik:ImageToolItem.CommandParameter>
                        </telerik:ImageToolItem>
                        <telerik:ImageToolItem ImageKey="Invert" Text="Invert Colors"  Command="commands:ImageEditorRoutedCommands.InvertColors" />
                    </telerik:ImageToolsSection>
     
                    <telerik:ImageToolsSection Header="Effects">
                        <telerik:ImageToolItem ImageKey="Sharpen" Text="Sharpen"  Command="commands:ImageEditorRoutedCommands.ExecuteTool">
                            <telerik:ImageToolItem.CommandParameter>
                                <tools:SharpenTool />
                            </telerik:ImageToolItem.CommandParameter>
                        </telerik:ImageToolItem>
                        <telerik:ImageToolItem ImageKey="Blur" Text="Blur"  Command="commands:ImageEditorRoutedCommands.ExecuteTool">
                            <telerik:ImageToolItem.CommandParameter>
                                <tools:BlurTool />
                            </telerik:ImageToolItem.CommandParameter>
                        </telerik:ImageToolItem>
     
                    </telerik:ImageToolsSection>
                </telerik:RadImageEditorUI.ImageToolsSections>
            </telerik:RadImageEditorUI>
     
        </Grid>
    </UserControl>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Media.Imaging;
    using System.IO;
     
    namespace Myproject
    {
        public partial class CustomImageEditor : UserControl
        {
            public byte[] ImageData
            {
                set
                {
                    try
                    {
                        MemoryStream memStream = new MemoryStream(value);
                        memStream.Seek(0, SeekOrigin.Begin);
     
                        BitmapImage imageSource = new BitmapImage();
                        imageSource.SetSource(memStream);
                         
                        Telerik.Windows.Media.Imaging.RadBitmap rbm = new Telerik.Windows.Media.Imaging.RadBitmap(imageSource);
                        RImgEditor.ImageEditor.Image = rbm;
                         
                    }
                    catch
                    {
                        MessageBox.Show("Unable to open image file");
                    }
                }
            }
     
            public CustomImageEditor()
            {
                InitializeComponent();
     
                RImgEditor.IsSaveButtonVisible=false;
                RImgEditor.IsOpenButtonVisible = false;
     
                RImgEditor.ImageEditor.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                RImgEditor.ImageEditor.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
     
            }
        }
    }

Back to Top