Telerik Forums
UI for WPF Forum
1 answer
174 views
Hi,
I'm developing with VS 2012 and Telerik control version 2013.2.724.40.
I tried to bind string values dynamically to the GridView in code.
The program first reads from a array, where it can decide the type of the column(e.g. string, double). If the data can be presented as a double value, then I create a customized GridView column with RadMaskedTextInput. I'd like to format the number by setting the Text property. The data binding works fine, however, it seems the numbers (e.g. 1000.1) are not shown as expected (e.g. 1,000.10). 

I could attach all source code if needed. Thanks in advance.

Regards,
Gong

public MainWindow()
{
    InitializeComponent();
 
    IList<DataHeader> headerList = DataService.Instance.HeaderList;
 
    for (int i = 0; i < headerList.Count; i++)
    {
        DataHeader curentHeader = headerList[i];
 
        GridViewBoundColumnBase column;
        if (curentHeader.Name == "AMOUNT")
        {
            column = new CGridViewNumColumn();
        }
        else
        {
            column = new GridViewDataColumn();
        }
 
        column.DataMemberBinding = new Binding("DataItemList[" + i + "]")
        {
            UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
        };
        column.Header = curentHeader.Caption;
        column.UniqueName = curentHeader.Name;
        GridControl.Columns.Add(column);
    }
    DataContext = DataService.Instance.Data;
}


internal class CGridViewNumColumn : GridViewBoundColumnBase
    {
        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
        {
            BindingTarget = RadMaskedTextInput.ValueProperty;
            var input = new RadMaskedTextInput
            {
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Culture = CultureInfo.GetCultureInfo("en-GB"),
                FormatString = "n2",
                Mask = "",
                MinWidth = 100,
                SelectionOnFocus = SelectionOnFocus.SelectAll
            };
            input.SetBinding(BindingTarget, CreateValueBinding());
            input.LostFocus += InputOnLostFocus;
            return input;
        }
 
        private void InputOnLostFocus(object sender, RoutedEventArgs routedEventArgs)
        {
            var input = sender as RadMaskedTextInput;
            if (input == null) throw new ArgumentNullException("sender");
            if (string.IsNullOrWhiteSpace(input.Value))
            {
                input.Value = string.Empty;
                return;
            }
            double value;
            //Format the number for frontend.
            const NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands;
            if (!double.TryParse(input.Value, style, input.Culture, out value))
            {
                input.Value = "0";
            }
            input.Text = value.ToString(input.FormatString, input.Culture);
 
            //Format the number for back-end. Extra precisions will be removed.
            if (!double.TryParse(input.Text, style, input.Culture, out value))
            {
                input.Value = "0";
            }
            input.Value = value.ToString(input.Culture);
        }
 
        private Binding CreateValueBinding()
        {
            var valueBinding = new Binding
            {
                Mode = BindingMode.TwoWay,
                NotifyOnValidationError = true,
                ValidatesOnExceptions = true,
                Path = new PropertyPath(DataMemberBinding.Path.Path)
            };
 
            return valueBinding;
        }
    }

Dimitrina
Telerik team
 answered on 02 Oct 2013
5 answers
222 views
Hello everybody,

I have a dataform with some fields declared as nullable double (i.e. double?). When I start my application, it is OK I have empty fields for the nullable parameters. But if I start to fill one of these fields and then I delete what I have written, I cannot let the field empty again. The field is boxed with a red frame and a validation exception disables end edit button.

Do you have an explanation and a method to let my fields empty ? I tried to modify the validation exception but I cannot find where they are defined.

Thank you !

Regards,

Thomas
Yoan
Telerik team
 answered on 01 Oct 2013
10 answers
256 views
Is there a way to change simple elements that are nested inside the ScheduleView's ControlTemplate, like NavigationHeader -- for example the border's background colour--using Style Setters?

Example: I'd like to apply the Windows8 theme, and then specify a different colour for NavigationHeader.

It seems a shame to generate the ControlTemplate's 6100 some-odd lines of XAML to change some minor elements in the ScheduleView's ControlTemplate.
Kalin
Telerik team
 answered on 01 Oct 2013
5 answers
97 views
Hello everyone,

 I am facing an issue using DataForm. I have an  abstract class IBacktestOption and several inherited classes. Let's take only two of them : OptionCall and CallSpread. These classes share 4 arguments with IBacktestOption and have their own arguments.

Here is the IBacktestOption class :
public abstract class IBacktestOption
   {
       #region fields
 
       private double mGearing;
       public double Gearing { get { return mGearing; } set { mGearing = value; } }
 
       private double? mGlobalCap;
       public double? GlobalCap { get { return mGlobalCap; } set { mGlobalCap = value; } }
 
       private double? mGlobalFloor;
       public double? GlobalFloor { get { return mGlobalFloor; } set { mGlobalFloor = value; } }
 
       public string Nom { get; set; }
 
 
       #endregion
 
       protected IBacktestOption(double aGearing, double? aGlobalCap, double? aGlobalFloor)
       {
           Gearing = aGearing;
           GlobalCap = aGlobalCap;
           GlobalFloor = aGlobalFloor;
       }
 
       public abstract Dictionary<DateTime, IResultatsBacktest> GetOptionResults(IBacktesting backtest);
 
       public abstract bool CheckOption();
 
   }



This is OptionCall class :
class OptionCall : IBacktestOption, IEditableObject, INotifyPropertyChanged
    {
 
        #region fields
 
        private double mStrike;
        public double Strike { get { return mStrike; } set { mStrike = value; } }
 
        OptionCallData backupOptParamData;
        private int mID;
 
        public struct OptionCallData
        {
            internal int ID;
            internal double Strike;
            internal double? CapGlobal;
            internal double? FloorGlobal;
            internal double Gearing;
        }
 
        public int ID
        {
            get { return mID; }
        }
 
        #endregion Fields
 
        #region constructors
 
        public static OptionCall CreateNewOptionCall(double strike, double gearing = 1, double? cap = null, double? floor = null)
        {
            return new OptionCall(strike,gearing,cap,floor);
        }
 
        public OptionCall(double strike, double gearing = 1, double? cap = null, double? floor = null) : base(gearing,cap,floor)
        {
            Strike = strike;
            Nom = "Call";
        }
 
        #endregion
 
        public override Dictionary<DateTime, IResultatsBacktest> GetOptionResults(IBacktesting backtest)
        {
            /* ... */
        }
 
        public override bool CheckOption()
        {
            return true;
        }
 
        #region Edition
 
        public void BeginEdit()
        {
 
        }
 
        public void CancelEdit()
        {
            mStrike = this.backupOptParamData.Strike;
            GlobalCap = this.backupOptParamData.CapGlobal;
            GlobalFloor = this.backupOptParamData.FloorGlobal;
            Gearing = this.backupOptParamData.Gearing;
        }
 
        public void EndEdit()
        {
            this.backupOptParamData.Strike = mStrike;
            this.backupOptParamData.CapGlobal = GlobalCap;
            this.backupOptParamData.FloorGlobal = GlobalFloor;
            this.backupOptParamData.Gearing = Gearing;
        }
 
 
        #endregion Edition
 
 
        #region Events
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        private void NotifyPropertyChanged(string info)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
 
        #endregion Events
 
 
    }

This is CallSpread class :
class CallSpread : IBacktestOption, IEditableObject, INotifyPropertyChanged
   {
       #region fields
 
       private double mStrike1;
       public double Strike1 { get { return mStrike1; } set { mStrike1 = value; } }
        
       private double mStrike2;
       public double Strike2 { get { return mStrike2; } set { mStrike2 = value; } }
 
       OptionCallData backupOptParamData;
       private int mID;
 
       public struct OptionCallData
       {
           internal int ID;
           internal double Strike1;
           internal double Strike2;
           internal double? CapGlobal;
           internal double? FloorGlobal;
           internal double Gearing;
       }
 
       public int ID
       {
           get { return mID; }
       }
 
 
 
       #endregion Fields
 
       #region constructors
 
       public static CallSpread CreateNewCallSpread(double strike1, double strike2, double gearing = 1, double? cap = null, double? floor = null)
       {
           return new CallSpread(strike1, strike2, gearing, cap, floor);
       }
 
       public CallSpread(double strike1, double strike2, double gearing = 1, double? cap = null, double? floor = null) : base(gearing,cap,floor)
       {
           Strike1 = Math.Min(strike1, strike2);
           Strike2 = Math.Max(strike1, strike2);
           Nom = "Call Spread";
       }
 
       #endregion
 
       public override Dictionary<DateTime, IResultatsBacktest> GetOptionResults(IBacktesting backtest)
       {
           /* ... */
       }
 
       public override bool CheckOption()
       {
           return true;
       }
 
 
       #region Edition
 
       public void BeginEdit()
       {
 
       }
 
       public void CancelEdit()
       {
           mStrike1 = this.backupOptParamData.Strike1;
           mStrike2 = this.backupOptParamData.Strike2;
           GlobalCap = this.backupOptParamData.CapGlobal;
           GlobalFloor = this.backupOptParamData.FloorGlobal;
           Gearing = this.backupOptParamData.Gearing;
       }
 
       public void EndEdit()
       {
           this.backupOptParamData.Strike1 = mStrike1;
           this.backupOptParamData.Strike2 = mStrike2;
           this.backupOptParamData.CapGlobal = GlobalCap;
           this.backupOptParamData.FloorGlobal = GlobalFloor;
           this.backupOptParamData.Gearing = Gearing;
       }
 
 
       #endregion Edition
 
 
       #region Events
 
       public event PropertyChangedEventHandler PropertyChanged;
 
       private void NotifyPropertyChanged(string info)
       {
           if (PropertyChanged != null)
               PropertyChanged(this, new PropertyChangedEventArgs(info));
       }
 
       #endregion Events
 
   }

In my view I have my DataForm declare like this :
<telerik:RadDataForm Grid.Column="1" Margin="12,0,6,21" Grid.ColumnSpan="2" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  ItemsSource="{Binding BacktestOpt}"
                                         CommandButtonsVisibility="Cancel,Commit,Edit,Navigation" Grid.Row="1" Height="456" Grid.RowSpan="2" />

And in my view model I initialize my Collection (I use a ViList, which is a structure almost equivalent to a simple List) with an element of OptionCall type :

private ViList<IBacktestOption> mBacktestOpt;
       public ViList<IBacktestOption> BacktestOpt
       {
           get
           {
               if (mBacktestOpt == null && Formule == 0)
               {
                   ViList<IBacktestOption> newBacktestOpt = new ViList<IBacktestOption>();
                   newBacktestOpt.Add(Creators.CreateNewOptionCall(0));
                   this.mBacktestOpt = new ViList<IBacktestOption>(newBacktestOpt);
                   Formule = PayoffFormule.CALL;
               }
               return mBacktestOpt;
           }
           set
           {
               mBacktestOpt = value;
               OnPropertyChanged("BacktestOpt");
           }
       }


When I start my application, everything is fine, I have what I want i.e. my DataForm with my 6 fields : "Strike", "ID", "Gearing", "GlobalCap", "GlobalFloor", "Nom".
In my page, I also have a RadComboBox which enables me to choose which formula I want to use. This combobox is binded to this field in my view model :
private PayoffFormule mFormule;
        public PayoffFormule Formule
        {
            get { return mFormule; }
            set
            {
                mFormule = value;            
                switch (mFormule)
                {
                    case PayoffFormule.CALL :
                        Backtest.Option = Creators.CreateNewOptionCall(0);
                        break;
                    case PayoffFormule.PUT :
                        Backtest.Option = Creators.CreateNewOptionPut(0);
                        break;
                    case PayoffFormule.ASIAN_CALL:
                        Backtest.Option = Creators.CreateNewAsianCall(0);
                        break;
                    case PayoffFormule.ASIAN_PUT:
                        Backtest.Option = Creators.CreateNewAsianPut(0);
                        break;
                    case PayoffFormule.CALL_SPREAD:
                        Backtest.Option = Creators.CreateNewCallSpread(0,0.15);
                        break;
                    default:
                        break;
                }
                BacktestOpt.Add(Backtest.Option);
                OnPropertyChanged("BacktestOpt");
                OnPropertyChanged("Formule");
            }
        }

When I use the ComboBox to change the formula, a new element is added to the DataForm and here is my issue : this new element only have the fields of IBacktestOption class. And when I use Navigation buttons to go back on my first element (OptionCall), the number of fields of the element have been reduced to 4 ("Gearing", "GlobalCap", "GlobalFloor", "Nom").

I want to know if it is possible to have the fields of the inherited classes instead of the ones of IBacktestOption.


Moreover, in reality I don't need to have a list of IBacktestOption in my DataForm, I only need to have the current option (the one which is selected in the combobox). So, I have tried to empty my List when I change the option type in the combobox :
private PayoffFormule mFormule;
       public PayoffFormule Formule
       {
           get { return mFormule; }
           set
           {
               mFormule = value;         
               BacktestOpt.RemoveAt(0);
               switch (mFormule)
               {
                   case PayoffFormule.CALL :
                       Backtest.Option = Creators.CreateNewOptionCall(0);
                       break;
                   case PayoffFormule.PUT :
                       Backtest.Option = Creators.CreateNewOptionPut(0);
                       break;
                   case PayoffFormule.ASIAN_CALL:
                       Backtest.Option = Creators.CreateNewAsianCall(0);
                       break;
                   case PayoffFormule.ASIAN_PUT:
                       Backtest.Option = Creators.CreateNewAsianPut(0);
                       break;
                   case PayoffFormule.CALL_SPREAD:
                       Backtest.Option = Creators.CreateNewCallSpread(0,0.15);
                       break;
                   default:
                       break;
               }
               BacktestOpt.Add(Backtest.Option);
               OnPropertyChanged("BacktestOpt");
               OnPropertyChanged("Formule");
           }
       }

It works, I have the good number of fields for each option type. But, I need to click on the Next Item Navigation Button to reach my element. Indeed, the first one is empty. It is not really handy for a user. So, I also want to know if there is a way to click on this button automatically.

Finally, I have a last request. As, I don't really need a List for my elements, I tried to use a IBacktestOption instead of a ViList<IBacktestOption> in BactestOpt field. But I didn't manage to have fields printed in DataForm, the DataForm was empty...

Thank you very much for your help.
Regards,

Thomas
Thomas
Top achievements
Rank 1
 answered on 01 Oct 2013
3 answers
107 views
Hello,

we are trying to connect this control to sybase iq database in order to improve the performance using OLAP technology, but the control's connectión only defines an user, password an query that execute a full scan read, so the perfrmance is not so good,

Do you know any solution to make a good connection to Sybase IQ?

Thanking in advance,

Regards,



Rosen Vladimirov
Telerik team
 answered on 01 Oct 2013
1 answer
79 views
I have a GridView where the GridViewColumns are created dynamically. We now have data in a column that can sometimes be null. I have kind of figured out how to use the Converter from the binding to change the value based on the value coming in - but this did not fix it. When I click on the filter It throws the error that must be of type Int64.

Here is the code that builds the column:
GridViewDataColumn col = new GridViewDataColumn();               
                col.Header = column.Name;               
                col.DataMemberBinding = binding;               
                col.DataType = column.DataType;                               
                col.IsSortable = true;
 
                if (column.DataType == typeof(Int64))
                {
                    col.DataMemberBinding.Converter = new LongConverter();
                }
 Here is the converter: 
public class LongConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //Int64? convertedValue = (Int64)value;
            //if (convertedValue.HasValue)
            //{
            //    return convertedValue.Value;
            //}
            //else
            //{
            //    return "";
            //}
 
            return "N/A";
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.ToString().ToUpper() == string.Empty)
            {
                return new Int64();
            }
            else
            {
                return Int64.Parse(value.ToString());
            }
        }
    }
You can see I commented all most of the code out on the converter. I was just trying to get it to work. The value was coming back as the type - so I'm not sure whats going on there.

So I really have to issues here:
1) How to properly set the converter on the column datamember binding.
2) Why does the filter still recognize the null value even though I set the value to "N/A"
Dimitrina
Telerik team
 answered on 01 Oct 2013
3 answers
86 views

I have a grid that we need to bold the text when the value changes...the code Im using is in the CellEditEnded event handler:

void GridView_CellEditEnded(object sender, GridViewCellEditEndedEventArgs)
{
if(e.NewData != e.OldData)
{
e.Cell.FontWeight = FontWeights.Bold;
}



This works fine...BUT when I switch rows the style goes back to its original style. My use case requires that ALL changed values remain bolded.

How can I achieve this?

Thanks,
Ron
Dimitrina
Telerik team
 answered on 01 Oct 2013
1 answer
150 views
Hey guys,

I have functionality to dynamically change themes via StyleManager.ApplicationTheme. Whenever the user changes themes, there is a roughly 20~30mb spike in memory usage that never seems to get garbage collected. Any idea on what would cause this?

The following code is used to dynamically change the theme:
public Theme ThisApplicationTheme
{
   get { return StyleManager.ApplicationTheme; }
   set
   {
      StyleManager.ApplicationTheme = value;
      var binding = new Binding("ThisApplicationTheme") { Source = this, Mode = BindingMode.OneWay };
       foreach (Window window in Application.Current.Windows)
       {
            foreach (var element in GetWindow(window).ChildrenOfType<FrameworkElement>().ToList())
            {
                 element.SetBinding(StyleManager.ThemeProperty, binding);
            }
       }
       Application.Current.MainWindow.SetBinding(StyleManager.ThemeProperty, binding);
   }
}

Thanks.
Pana
Telerik team
 answered on 01 Oct 2013
1 answer
132 views
Hi,

I have a chart like the one in the image,the code is the next:

<telerik:RadChart Name="RadChartDemo" Grid.ColumnSpan="3" Content="" Margin="10" Grid.Row="2" BorderThickness="0">
           <telerik:RadChart.DefaultView>
               <telerik:ChartDefaultView>
                   <telerik:ChartDefaultView.ChartArea>
                       <telerik:ChartArea>
                           <telerik:ChartArea.ZoomScrollSettingsY>
                               <telerik:ZoomScrollSettings ScrollMode="ScrollAndZoom"/>
                           </telerik:ChartArea.ZoomScrollSettingsY>
                           <telerik:ChartArea.ZoomScrollSettingsX>
                               <telerik:ZoomScrollSettings ScrollMode="ScrollAndZoom"/>
                           </telerik:ChartArea.ZoomScrollSettingsX>
                       </telerik:ChartArea>
                   </telerik:ChartDefaultView.ChartArea>
                   <telerik:ChartDefaultView.ChartTitle>
                       <telerik:ChartTitle Content="Tons Per Day" HorizontalAlignment="Center"/>
                   </telerik:ChartDefaultView.ChartTitle>
               </telerik:ChartDefaultView>
           </telerik:RadChart.DefaultView>
       </telerik:RadChart>

And I create the series using SeriesMapping and ItemMapping. When I run the application I can see both scroll bars but it seems to be disable, I can't scroll nor zoom the chart.

Do I have something missing?

Regards,

Alberto
Petar Kirov
Telerik team
 answered on 01 Oct 2013
0 answers
79 views
Hi
Is there any way to assign tool-tip to text in RadRichTextBox.

I had tried by assigning Cross-reference bookmark by using editor.InsertBookmark(...) and editor.InsertCrossReferenceToBookmark(... , ... , ..) method. Bookmark is implemented but there is tool-tip is missing.

So how to enable tool-tip which normally shows in MS word.

Any alternate ways?

Regards
Sopan Vaidya
Sopan
Top achievements
Rank 1
 asked on 01 Oct 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?